This project starts an API Gateway (Traefik) on your local server.
It is configured to:
- Use Docker as a service provider.
- Expose and listen on port 443 (HTTPS).
- Redirect incoming traffic on port 80 to 443.
- Automatically handle SSL certificates and DNS via DuckDNS.
DuckDNS offers 5 free subdomains, which you can use to set up your apps.
- Access your router settings (often at
http://192.168.1.1
). - Forward port 443 (HTTPS) to the local server running Traefik.
-
Create a free account on DuckDNS.
-
Link your public IP address to one or more DuckDNS subdomains of your choice.
-
Initialize the
.env
file:cp .env.sample .env
-
Edit the
.env
file to include your email address, DuckDNS token, and subdomains. For example:[email protected] DUCKDNS_TOKEN=4f51... DUCKDNS_DOMAINS=domain1,domain2
- DUCKDNS_EMAIL: Your email address.
- DUCKDNS_TOKEN: The token from the DuckDNS dashboard.
- DUCKDNS_DOMAINS: A comma-separated list of the subdomain names you created on DuckDNS (e.g., if your DuckDNS subdomain is
domain1.duckdns.org
, just putdomain1
here).
Note: Each domain listed in
DUCKDNS_DOMAINS
corresponds todomain-name.duckdns.org
. -
Create an empty
homeserver-https-cert.json
file and secure it by setting permissions to600
:touch homeserver-https-cert.json chmod 600 homeserver-https-cert.json
-
Traefik will automatically renew certificates before they expire.
-
Start Traefik:
docker network create homeserver docker compose up -d firefox http://localhost:8080
-
Traefik Dashboard
- By default, the Traefik dashboard is exposed (insecure) at http://your-server:8080.
- You can secure or disable the dashboard by removing
--api.insecure=true
from the Traefik configuration.
-
Certificate Renewal
- Traefik automatically renews Let’s Encrypt certificates before they expire.
-
Additional Applications
- You can add other Docker services by labeling them for Traefik with a different
Host()
orPathPrefix()
rule.
- You can add other Docker services by labeling them for Traefik with a different
If your public IP changes frequently (e.g., residential internet service), you can keep your DuckDNS subdomains updated automatically:
-
Auto-Refresh Script
- Create a script (e.g.,
autorefresh-dns.sh
) that detects your IPv4/IPv6 and updates DuckDNS for each subdomain inDUCKDNS_DOMAINS
. - Make sure it reads your DuckDNS token and subdomains from the
.env
file.
- Create a script (e.g.,
-
Cron Scheduling
- Give execution permission:
chmod +x autorefresh-dns.sh
- Schedule it in cron (e.g., every 5 minutes):
crontab -e */5 * * * * /path/to/autorefresh-dns.sh
- Give execution permission:
This ensures that your DuckDNS subdomains always match your current public IP, keeping your SSL certificates valid and your services accessible.