Why Traefik is a Good Fit for Home NAS and Pi‑Hole
If you’re already running a NAS (Synology, QNAP, or a DIY Raspberry Pi) and a Pi‑Hole instance, you’re probably exposing them through a static IP or a dynamic‑DNS service. The easiest way to add HTTPS without juggling self‑signed certs is to let Traefik be the reverse proxy and hand off certificate acquisition to Let’s Encrypt automatically. Traefik is lightweight, runs in a container, and can be configured with a single YAML file. Below is a step‑by‑step guide that shows how to set it up on a Raspberry Pi running Raspberry OS (Debian‑based) and how to route traffic to both services while keeping the configuration simple.
Prerequisites
| Item | Why it matters | Typical command |
|---|---|---|
| Raspberry Pi 4 (or similar) with at least 2 GB RAM | Traefik runs in a container; 2 GB is enough for a few services | sudo apt update && sudo apt upgrade |
| Docker (or Podman) installed | Traefik is distributed as a container image | sudo apt install docker.io |
| Domain name with DNS A record pointing to your public IP | Let’s Encrypt needs a public domain | dig @8.8.8.8 yourdomain.com |
| Port 80 and 443 open on your router | Traefik listens on these ports | sudo ufw allow 80,443/tcp |
Basic knowledge of docker-compose |
Makes configuration easier | sudo apt install docker-compose |
1. Create a Traefik Directory
mkdir -p ~/traefik
cd ~/traefik
Keeping everything in one folder makes version control and backups trivial.
2. Traefik Configuration File
Create traefik.yml:
# traefik.yml
log:
level: INFO
entryPoints:
web:
address: ":80"
websecure:
address: ":443"
providers:
docker:
exposedByDefault: false
certificatesResolvers:
letsencrypt:
acme:
email: [email protected]
storage: acme.json
httpChallenge:
entryPoint: web
Key points
| Section | Purpose | Trade‑off |
|---|---|---|
log.level |
Controls verbosity | DEBUG is useful during setup but noisy in production |
entryPoints |
Exposes HTTP/HTTPS | Adding TLS‑ALPN‑01 challenge requires port 443 only |
providers.docker |
Lets Traefik read Docker labels | exposedByDefault: false forces explicit exposure, reducing accidental leaks |
certificatesResolvers |
Configures Let’s Encrypt | Using httpChallenge is simpler than DNS‑01 but requires port 80 open |
3. Docker‑Compose File
Create docker-compose.yml:
version: "3.8"
services:
traefik:
image: traefik:v3.0
container_name: traefik
restart: unless-stopped
command:
- --configFile=/etc/traefik/traefik.yml
ports:
- "80:80"
- "443:443"
volumes:
- ./traefik.yml:/etc/traefik/traefik.yml:ro
- ./acme.json:/acme.json:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- web
nas:
image: your-nas-image
container_name: nas
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.nas.rule=Host(`nas.yourdomain.com`)"
- "traefik.http.routers.nas.entrypoints=websecure"
- "traefik.http.routers.nas.tls.certresolver=letsencrypt"
- "traefik.http.services.nas.loadbalancer.server.port=80"
networks:
- web
pihole:
image: pihole/pihole:latest
container_name: pihole
restart: unless-stopped
environment:
- TZ=Europe/London
- WEBPASSWORD=change_me
labels:
- "traefik.enable=true"
- "traefik.http.routers.pihole.rule=Host(`pi.hole.yourdomain.com`)"
- "traefik.http.routers.pihole.entrypoints=websecure"
- "traefik.http.routers.pihole.tls.certresolver=letsencrypt"
- "traefik.http.services.pihole.loadbalancer.server.port=80"
volumes:
- "./pihole/etc-pihole:/etc/pihole"
- "./pihole/etc-dnsmasq.d:/etc/dnsmasq.d"
networks:
- web
networks:
web:
external: false
Why this layout?
- Separate services – Each container gets its own labels. This keeps the Traefik configuration declarative and avoids hard‑coding ports.
- TLS termination – All traffic to the services is encrypted end‑to‑end. The services themselves can stay on HTTP inside the LAN.
- Automatic certificate renewal – Traefik handles renewal silently; you only need to keep the container running.
4. Secure the ACME Storage
Traefik writes the Let’s Encrypt certificates to acme.json. It must be writable by the container but not readable by other users.
touch acme.json
chmod 600 acme.json
5. Bring Everything Up
docker compose up -d
After a minute, check the logs:
docker compose logs -f traefik
You should see something like:
2026-11-29 12:34:56.789Z INFO: Starting Traefik
2026-11-29 12:35:01.123Z INFO: Acme: new challenge for nas.yourdomain.com
2026-11-29 12:35:02.456Z INFO: Acme: challenge solved, certificate issued
If you see errors about acme.json permissions or DNS resolution, double‑check the steps above.
6. Verify HTTPS
Open a browser and navigate to:
https://nas.yourdomain.com– You should see the NAS web UI.https://pi.hole.yourdomain.com– Pi‑Hole’s dashboard should load.
Both should display a valid certificate from Let’s Encrypt. If you get a “self‑signed” warning, the challenge failed; check the Traefik logs for the exact error.
7. Common Pitfalls & Troubleshooting
| Symptom | Likely Cause | Fix |
|---|---|---|
Traefik logs show acme: challenge failed |
DNS A record not pointing to the public IP | Verify dig yourdomain.com returns the correct IP |
| Services not reachable via HTTPS | Docker container port mismatch | Ensure traefik.http.services.<name>.loadbalancer.server.port matches the service’s internal port |
| Traefik container crashes on start | acme.json permissions |
chmod 600 acme.json |
| Pi‑Hole UI shows “Not secure” | Mixed content (HTTP resources) | Pi‑Hole must be served over HTTPS; check the pihole service port is 80 inside the container, not 443 |
8. Optional Enhancements
8.1 HTTP to HTTPS Redirection
Add a middleware to force HTTPS:
labels:
- "traefik.http.middlewares.redirect-to-https.redirectScheme.scheme=https"
- "traefik.http.routers.nas.middlewares=redirect-to-https"
- "traefik.http.routers.pihole.middlewares=redirect-to-https"
8.2 Basic Authentication
If you don’t want the NAS or Pi‑Hole exposed to the public internet, add HTTP auth:
labels:
- "traefik.http.middlewares.auth.basicauth.users=admin:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"
- "traefik.http.routers.nas.middlewares=auth"
Generate the hash with openssl passwd -apr1.
8.3 Rate Limiting
Prevent abuse by limiting requests:
labels:
- "traefik.http.middlewares.ratelimit.ratelimit.average=100"
- "traefik.http.middlewares.ratelimit.ratelimit.burst=50"
- "traefik.http.routers.nas.middlewares=ratelimit"
9. Security Considerations
- Least‑privilege –
exposedByDefault: falseensures only services with explicit labels are reachable. - TLS only – By default, Traefik serves only HTTPS. If you need HTTP for internal traffic, add a separate entry point.
- Container isolation – Run Traefik and your services in separate containers; avoid running them as root inside the container.
- Regular updates – Keep the Traefik image up to date.
docker pull traefik:v3.0followed bydocker compose up -dwill upgrade without downtime.
10. Scaling Beyond Two Services
If you add more services (e.g., a home‑assistant instance or a media server), simply add new services to the docker-compose.yml with the same label pattern. Traefik will pick them up automatically. For a larger homelab, consider:
- Using a dedicated reverse‑proxy container on a separate host.
- Splitting the DNS into subdomains (e.g.,
media.yourdomain.com). - Leveraging Traefik’s dynamic configuration via file providers for more complex routing rules.
11. Resources
- Official Traefik documentation – https://doc.traefik.io/traefik/
- Let’s Encrypt ACME protocol – https://letsencrypt.org/docs/acme-protocol/
- Docker Compose reference – https://docs.docker.com/compose/
See also
- Using jq to extract a single field from nested JSON logs
- Preventing /tmp from Over‑filling: a quick Ubuntu desktop fix
- How to Stop a Log File from Filling Your SSD in 5 Minutes
- When nftables silently drops your local web server: a step‑by‑step debug
- Running a FreeNAS Backup Server with rsync and Snapshots on a Raspberry Pi 4