Reverse Proxy using Traefik
Traefik template for hosting multiple containers on the same port via reverse proxy.
- Uses the Docker version of Traefik (in
./reverse-proxy
) - Includes two sample apps running a basic httpd server for testing (in
./site1
,./site2
) - Configured for secure dashboard and apps with auto-generated SSL certs
- Cert config is accessible via volume in
./reverse-proxy/letsencrypt/acme.json
when the container has been run
htpasswd -c reverse-proxy/.users admin
Follow the prompts to generate the admin user. Repeat for any additional users required.
- Cert generation email (
certificatesresolvers.myresolver.acme.email
) - Dashboard domain (
traefik.http.routers.dashboard.rule
)
While debugging uncomment the following command args in reverse-proxy/docker-compose.yml
:
# - "--log.level=DEBUG"
: to show more verbose log messages# - "--certificatesresolvers.myresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
: to use letsencrypt staging server for test certificates
This will likely result in a ERR_CERT_AUTHORITY_INVALID
when accessing URLs.
They are uncommented by default. Remove or comment them again when you're ready to deploy.
Don't forget to clear the old test certificates and re-run the container after disabling the staging server:
cd ./reverse-proxy
docker-compose down
rm -rf ./letsencrypt
docker-compose up -d --build
- Domain - replace
site1.example.com
insite1/docker-compose.yml
- Router - replace
site1
in all occurrences oftraefik.http.routers.site1
with the real site name insite1/docker-compose.yml
Repeat for each additional app.
NOTE: You can modify each app's Dockerfile
and docker-compose.yml
as long as they expose the port correctly and the Traefik labels are maintained and configured.
cd ./reverse-proxy
docker-compose up -d --build
docker-compose logs -f
cd ./site1
docker-compose up -d --build
cd ./site1
docker-compose up -d --build
Create ANAME DNS records pointing each configured domain to the IP address of server you're hosting Traefik on.
- Open the configured dashboard domain in your browser.
- For example, if I configured
dev.example.com
as the dashboard domain,https://dev.example.com
- Open the configured URL for each running app.
- For example,
https://site1.example.com