tomwojcik/homeserver-traefik-portainer
About
My homeserver setup. Everything managed securely using Portainer.
Systems & InfrastructureMeasured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Originalhomeserver-traefik-portainer
A complete homeserver setup using Traefik reverse proxy with automatic HTTPS and Portainer for easy container management. Torrenting runs inside a VPN kill switch. Nothing is published outside the LAN unless you opt in.
Features
✅ Local-first architecture - Fast streaming without internet dependencies
✅ Automatic HTTPS - Set-and-forget SSL certificates via Let's Encrypt
✅ VPN-protected torrenting - qBittorrent lives inside a Gluetun WireGuard kill switch
✅ Easy service deployment - Deploy services via Portainer's web UI
✅ Nothing public by default - No ports forwarded, no tunnel; every app keeps its own login
✅ Service auto-discovery - Traefik automatically detects new services
✅ No port conflicts - Everything routed through Traefik on 80/443
Quick Start
1. Configure Environment
cp .env.example .env
# Edit .env and configure:
# - SERVER_DOMAIN=example.com
# - [email protected]
# - CF_DNS_API_TOKEN=your_cloudflare_dns_token
# (VPN credentials are entered in the Portainer form of the media-server template, not here)
Setting up Cloudflare DNS API Token
For automatic HTTPS certificates, you need a Cloudflare API token with DNS permissions:
- Buy a domain - Cloudflare offers domains at cost (no markup) and provides excellent DNS management
- Create API Token:
- Go to Cloudflare API Tokens
- Click "Create Token"
- Use "Custom token" template
- Permissions:
- Zone:Zone:Read
- Zone:DNS:Edit
- Zone Resources:
- Include: Specific zone:
your-domain.com
- Include: Specific zone:
- Client IP Address Filtering: Leave empty (optional)
- Click "Continue to summary" → "Create Token"
- Save the token - You'll use this for
CF_DNS_API_TOKENin your.envfile
Alternative DNS Providers: If not using Cloudflare, check Traefik's supported ACME providers and adjust the configuration accordingly.
2. Set Up DNS
Local DNS Configuration
Point *.example.com to your NAS IP address:
- Router DNS: Add wildcard DNS entry
- Pi-hole: Add local DNS record
- Hosts file:
192.168.1.100 jellyfin.example.com(etc.)
Cloudflare DNS Configuration
For external access and Let's Encrypt certificates:
- In Cloudflare Dashboard: Go to your domain → DNS
- Add DNS Record:
- Type:
A - Name:
*(wildcard) - IPv4 address: Your NAS IP address (e.g.,
192.168.1.100) - Proxy status: ☁️ Disabled (DNS only, not proxied)
- TTL: Auto
- Type:
- Click Save
Important: The proxy status must be disabled for Let's Encrypt DNS challenges to work properly.
3. Start Core Services
docker-compose up -d
This starts:
- Traefik v3.8.0 (reverse proxy with automatic HTTPS)
- Portainer 2.45.4 (container management)
- Cloudflared (optional; only used if you set up a Cloudflare Tunnel)
4. Deploy Services via Portainer
IMPORTANT: Deploy in this order!
- Access Portainer:
https://portainer.example.com - Configure App Templates:
- Go to Settings > App Templates
- Set URL:
https://raw.githubusercontent.com/tomwojcik/homeserver-traefik-portainer/master/template.json
- Deploy "Complete Media Server with VPN": Gluetun is part of that stack. Read stacks/media-server/readme.md first for the Synology prerequisites (TUN boot task, directory ownership).
- Deploy other services: Any order
5. Keep Running Stacks Up to Date
On the NAS, in this checkout:
git pull
make sync # or: scripts/sync-stacks.sh (it re-runs itself with sudo)
It finds which of the repo's stacks run on the NAS and shows how each deployed compose file differs
from the repo. After one confirmation it writes the repo's version and runs docker compose up -d
for each stack that differs. Portainer stacks keep their variables, and Portainer's editor shows
the new file. Stacks that aren't deployed are left alone. Services that are down (stopped or
crashed, or whole stacks that are down) are started, and containers on another image than the
file pins are recreated; to keep a service off, comment it out in the repo. It stops at the first
stack that fails and prints how to roll back.
Available Services
Deploy any of these through Portainer's App Templates:
Media & Entertainment
- Complete Media Server with VPN - one stack: Gluetun + qBittorrent (VPN), Prowlarr, Sonarr, Radarr, Lidarr, Bazarr, Jellyfin, Navidrome, Seerr (Jellyseerr). See stacks/media-server
- MeTube - YouTube downloader (not routed through the VPN)
Productivity
- Nextcloud - File sync and collaboration
- Vaultwarden - Self-hosted password manager (Bitwarden-compatible)
- Heimdall - Dashboard for organizing services
- Uptime Kuma - Service monitoring
Development
- Gitea/Gogs - Git repositories
- Docker Registry - Private container registry
- n8n - Workflow automation
Utilities
- Dozzle - Container log viewer
- CyberChef - Data transformation tools
- RustFS - S3-compatible object storage (replaces MinIO)
Service URLs
After setup, your services will be available at:
- https://traefik.example.com (Traefik dashboard)
- https://portainer.example.com (Container management)
- https://jellyfin.example.com (Media streaming - local speed)
- https://sonarr.example.com (TV show management)
- https://qbittorrent.example.com (Torrents via VPN)
- https://metube.example.com (YouTube downloads)
- https://nextcloud.example.com (File sync)
- https://vaultwarden.example.com (Password manager)
- https://uptime.example.com (Service monitoring)
Containers talk to each other by container name (http://radarr:7878), never through these
public hostnames: that would loop out through Traefik for no benefit and add a DNS and
certificate dependency to every sync.
Network Architecture
Local Access (Primary)
Local Device → Router DNS → NAS:443 → Traefik → Service
Benefits: Full bandwidth, no internet dependency, lowest latency
External Access (Optional)
None by default. If you publish a service through a Cloudflare Tunnel, put Cloudflare Access in front of its hostname: the app's own login is the only other layer.
VPN Protection (Torrents)
qbittorrent → Gluetun (WireGuard, kill switch) → Internet
prowlarr / *arr / metube → Internet directly
Only the torrent transfer is VPN'd. Indexer searches and YouTube downloads use the NAS IP.
VPN Setup (Critical for Torrents)
Gluetun is a service inside the media-server stack (WireGuard only). Credentials go into the
template form: VPN_SERVICE_PROVIDER, WIREGUARD_PRIVATE_KEY, WIREGUARD_ADDRESSES,
SERVER_COUNTRIES.
Verify the VPN
docker logs gluetun # look for "Wireguard setup is complete" and a healthy check
docker exec gluetun cat /tmp/gluetun/ip # VPN server IP, not your real IP (the image has no curl)
docker stop gluetun # kill-switch test: qbittorrent must lose connectivity
Accessing qBittorrent
https://qbittorrent.<domain>. Sonarr and Radarr reach it as host gluetun, port 8080.
Never publish port 8080 on the host: that bypasses Traefik and TLS.
Workflow after setup
- Request media: Seerr → Sonarr/Radarr
- Automatic download: Prowlarr finds it, qBittorrent downloads it through the VPN
- Import: Sonarr/Radarr/Lidarr hardlink it into
/data/tv,/data/moviesor/data/music, Bazarr adds subtitles - Watch / listen: Jellyfin (video and music, casts to Chromecast), Navidrome (music, for Subsonic apps)
Adding New Services
Method 1: Portainer App Templates (Recommended)
- Deploy service through Portainer App Templates
- Service automatically gets Traefik labels
- Instantly available at
https://service.example.com
Method 2: External Repository
Perfect for deploying your own applications:
services:
my-app:
build: .
container_name: my-app
networks:
- homeserver
restart: unless-stopped
labels:
- "my.zone=homeserver"
- "traefik.enable=true"
- "traefik.http.routers.myapp.rule=Host(`myapp.${SERVER_DOMAIN}`)"
- "traefik.http.routers.myapp.entrypoints=websecure"
- "traefik.http.routers.myapp.tls.certresolver=myresolver"
- "traefik.http.services.myapp.loadbalancer.server.port=3000"
networks:
homeserver:
name: homeserver
external: true
If your service talks to another container, use its container name (http://sonarr:8989),
not the public hostname.
Method 3: Manual Stack Deployment
- In Portainer: Stacks → Add Stack → Git Repository
- Enter your repo URL:
https://github.com/yourusername/project - Add environment variables: Include
SERVER_DOMAIN - Deploy: Service available at
https://project.example.com
External Access Configuration
Nothing is published outside the LAN by default.
Option 1: Cloudflare Tunnel (if you need it)
Run cloudflared from the root compose with a tunnel token and add public hostnames for the
services you want, origin https://traefik:443, and put Cloudflare Access in front of every
hostname you publish.
Option 2: Port Forwarding
Not recommended: it exposes every routed hostname to the internet.
Synology NAS Setup
Synology DSM uses ports 80 and 443 for its web interface, which conflicts with Traefik. Here's how to resolve this:
Port Conflict Resolution
Change DSM ports (recommended approach):
sed -i -e 's/80/81/' -e 's/443/444/' /usr/syno/share/nginx/server.mustache /usr/syno/share/nginx/DSM.mustache /usr/syno/share/nginx/WWWService.mustacheRestart nginx service:
- DSM < 7:
synoservicecfg --restart nginx - DSM ≥ 7:
sudo systemctl restart nginx
- DSM < 7:
Access DSM: Use
http://nas-ip:81orhttps://nas-ip:444instead of default ports
Alternative Approach
Instead of changing DSM ports, you can modify Traefik to use different ports in the docker-compose.yml:
ports:
- "8080:80" # HTTP
- "8443:443" # HTTPS
Then access services via https://service.example.com:8443
Troubleshooting
HTTPS Issues
- Check DNS: Ensure
*.example.compoints to NAS IP - Check certificates:
docker logs traefik - Cloudflare API: Verify
CF_DNS_API_TOKENis correct - Domain ownership: Must control DNS for Let's Encrypt
VPN Issues
- Check gluetun logs:
docker logs gluetun - Verify credentials: WireGuard keys must be valid
- Test connection:
docker exec gluetun cat /tmp/gluetun/ip - Port forwarding: Check if VPN supports it
Service Not Accessible
- Check Traefik dashboard:
https://traefik.example.com - Verify labels: Service must have proper Traefik labels
- Check networks: Service must be on
homeservernetwork - DNS cache: Clear browser/system DNS cache
Portainer Security Timeout
If Portainer shows "timeout.html" or security timeout message:
- Cause: Portainer requires admin setup within 2 minutes of first start
- Fix:
docker restart portainer # Immediately go to portainer.example.com and create admin user - Alternative: Access directly via
http://nas-ip:9000during setup - Note: This only happens on first setup - once admin is created, normal access works
Published Ports Bypass Traefik
A ports: mapping makes a service reachable at nas-ip:port in plain HTTP, outside Traefik
and TLS. Keep ports unpublished in production; if a hostname returns 404, check
the router in the Traefik dashboard and the container's labels instead.
Performance Issues
- Local vs External: Use local URLs for best performance
- GPU transcoding: enabled in media-server (Jellyfin gets the render node); see
stacks/media-server/known-issues.md - Storage: Ensure fast storage for media files
Security Best Practices
Network Isolation
- Torrent traffic only leaves through the Gluetun kill switch
- No host ports published by the media-server stack (only Traefik 80/443)
Access Control
- Security headers on every media-server router. No IP allow-list: Synology's Docker presents every LAN client as the bridge gateway, so one cannot work (see
stacks/media-server/known-issues.mditem 8) - Every app keeps its own login enabled; Seerr's login page is rate-limited
- External: nothing by default; opt-in per router (see External Access)
Containers
- Images pinned to exact versions
- LinuxServer apps run as your user with a read-only root filesystem and no capabilities
- Memory and process limits, log rotation and health checks on every media-server service
Certificate Management
- Automatic Let's Encrypt renewal
- Wildcard certificates for all subdomains
- DNS challenge (no port 80 requirement)
Performance Optimization
Media Streaming
- Local access only: No tunnel overhead
- Direct file access: Mount media directories properly
- GPU acceleration: on by default in the media-server stack (Intel QuickSync via the render node)
Resource Management
- Health checks: every media-server service has one;
deunhealthrestarts qBittorrent when it loses gluetun's network - Resource limits: memory limits on every media-server service (scale down on a small NAS;
cpusandpidsare not supported by the DSM kernel) - Monitoring: Use cAdvisor and Uptime Kuma
Deployment Order (Important!)
- Core services:
docker-compose up -d(Traefik + Portainer) - Media server: deploy "Complete Media Server with VPN" (Gluetun is inside it; qBittorrent waits for it)
- Other services: Deploy in any order
Contributing
This is a production-ready homeserver setup optimized for performance and security. If you find it useful:
- ⭐ Star the repository
- 🍴 Fork for your own modifications
- 📝 Share improvements via issues/PRs
References
Explore related projects
Loading…