{"id":1877,"date":"2026-09-05T09:36:13","date_gmt":"2026-09-05T04:06:13","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/how-to-setup-traefik-reverse-proxy-docker-ssl\/"},"modified":"2026-09-05T12:58:49","modified_gmt":"2026-09-05T07:28:49","slug":"how-to-setup-traefik-reverse-proxy-docker-ssl","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/how-to-setup-traefik-reverse-proxy-docker-ssl\/","title":{"rendered":"How to Set Up Traefik Reverse Proxy with Docker and Auto Let&#8217;s Encrypt SSL"},"content":{"rendered":"<h2>Why Traefik Has Revolutionized Container Routing<\/h2>\n<p>In traditional multi-container web architectures, deploying a new microservice behind Nginx or Apache requires manually writing a new virtual host configuration file, obtaining SSL certificates via Certbot, and reloading the web server daemon. When containers are scaled up or down frequently in Docker Compose, this manual configuration process is error-prone and tedious.<\/p>\n<p><strong>Traefik<\/strong> is a modern HTTP reverse proxy and ingress controller designed specifically for containerized microservices. By listening directly to the Docker socket API, Traefik dynamically discovers newly created containers, parses their metadata labels, creates routing rules on the fly, and automatically provisions Let&#8217;s Encrypt SSL certificates without requiring a single server reload.<\/p>\n<p>In this production-ready deployment guide, we will configure Traefik v3 on Ubuntu 24.04\/22.04 LTS using Docker Compose, secure the Traefik management dashboard, and route traffic to backend containers using dynamic Docker labels.<\/p>\n<h2>Step 1: Preparing Directory Structure &amp; ACME Storage<\/h2>\n<p>Create a dedicated directory for Traefik and initialize the <code>acme.json<\/code> certificate store with strict <code>600<\/code> permissions:<\/p>\n<pre><code># Create Traefik directory structure\nsudo mkdir -p \/var\/www\/traefik\ncd \/var\/www\/traefik\n\n# Create acme.json file with restricted permissions\ntouch acme.json\nchmod 600 acme.json\n\n# Create dedicated Docker network\ndocker network create web-gateway<\/code><\/pre>\n<h2>Step 2: Creating Traefik Docker Compose Stack<\/h2>\n<p>Create <code>\/var\/www\/traefik\/docker-compose.yml<\/code>:<\/p>\n<pre><code>services:\n  traefik:\n    image: traefik:v3.1\n    container_name: traefik_router\n    restart: always\n    command:\n      - \"--api.dashboard=true\"\n      - \"--providers.docker=true\"\n      - \"--providers.docker.exposedbydefault=false\"\n      - \"--entryPoints.web.address=:80\"\n      - \"--entryPoints.websecure.address=:443\"\n      # Global HTTP to HTTPS Redirection\n      - \"--entryPoints.web.http.redirections.entryPoint.to=websecure\"\n      - \"--entryPoints.web.http.redirections.entryPoint.scheme=https\"\n      # ACME Let's Encrypt Automated SSL\n      - \"--certificatesresolvers.myresolver.acme.tlschallenge=true\"\n      - \"--certificatesresolvers.myresolver.acme.email=admin@example.com\"\n      - \"--certificatesresolvers.myresolver.acme.storage=\/acme.json\"\n    ports:\n      - \"80:80\"\n      - \"443:443\"\n    networks:\n      - web-gateway\n    volumes:\n      - \/var\/run\/docker.sock:\/var\/run\/docker.sock:ro\n      - .\/acme.json:\/acme.json\n    labels:\n      - \"traefik.enable=true\"\n      # Dashboard Routing &amp; Basic Auth Protection\n      - \"traefik.http.routers.traefik-dashboard.rule=Host(`traefik.example.com`)\"\n      - \"traefik.http.routers.traefik-dashboard.service=api@internal\"\n      - \"traefik.http.routers.traefik-dashboard.entrypoints=websecure\"\n      - \"traefik.http.routers.traefik-dashboard.tls.certresolver=myresolver\"\n      - \"traefik.http.routers.traefik-dashboard.middlewares=auth\"\n      # Generate hashed password with: htpasswd -nb admin yourpassword\n      - \"traefik.http.middlewares.auth.basicauth.users=admin:$$apr1$$xyz$$randomhash\"\n\nnetworks:\n  web-gateway:\n    external: true<\/code><\/pre>\n<h2>Step 3: Launching Traefik Gateway<\/h2>\n<pre><code># Start Traefik in detached daemon mode\ndocker compose up -d\n\n# Verify Traefik logs and ACME challenges\ndocker compose logs -f<\/code><\/pre>\n<h2>Step 4: Deploying Microservice Containers with Traefik Labels<\/h2>\n<p>To expose any application container (e.g. Next.js, WordPress, or Go API) through Traefik with automated HTTPS, simply attach the <code>web-gateway<\/code> network and declare Traefik labels in its compose file:<\/p>\n<pre><code>services:\n  whoami_app:\n    image: traefik\/whoami\n    container_name: demo_whoami\n    restart: always\n    networks:\n      - web-gateway\n    labels:\n      - \"traefik.enable=true\"\n      - \"traefik.http.routers.whoami.rule=Host(`demo.example.com`)\"\n      - \"traefik.http.routers.whoami.entrypoints=websecure\"\n      - \"traefik.http.routers.whoami.tls.certresolver=myresolver\"\n      - \"traefik.http.services.whoami.loadbalancer.server.port=80\"\n\nnetworks:\n  web-gateway:\n    external: true<\/code><\/pre>\n<p>When you run <code>docker compose up -d<\/code> on the application, Traefik immediately discovers the new container, issues a Let&#8217;s Encrypt certificate, and begins routing HTTPS traffic to <code>https:\/\/demo.example.com<\/code> in seconds!<\/p>\n<h2>Traefik vs Traditional Nginx Routing Comparison<\/h2>\n<table style=\"width: 100%;border-collapse: collapse;margin: 20px 0;border: 1px solid #334155\">\n<thead>\n<tr style=\"background-color: #0f172a;color: #38bdf8\">\n<th style=\"padding: 12px;border: 1px solid #334155\">Feature \/ Workflow<\/th>\n<th style=\"padding: 12px;border: 1px solid #334155\">Traefik Dynamic Proxy<\/th>\n<th style=\"padding: 12px;border: 1px solid #334155\">Traditional Static Nginx<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background-color: #1e293b;color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>Adding New Microservices<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>Automatic via Docker Labels<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\">Manual vhost config file creation<\/td>\n<\/tr>\n<tr style=\"background-color: #0f172a;color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>SSL Certificate Management<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>Built-in ACME Automated Issuance<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\">Requires Certbot cron configuration<\/td>\n<\/tr>\n<tr style=\"background-color: #1e293b;color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>Server Reloads on Changes<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>Zero Reloads (Live Dynamic Config)<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\">Requires <code>systemctl reload nginx<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Implementing Rate Limiting &amp; Security Middlewares in Traefik<\/h2>\n<p>Protect your containerized microservices from denial-of-service floods and brute-force scans using Traefik&#8217;s built-in rate-limiting and security header middlewares:<\/p>\n<pre><code># Add Security &amp; Rate-Limit Middlewares in docker-compose.yml\nlabels:\n  # Rate limit: Maximum 30 requests per second with burst capacity of 50\n  - \"traefik.http.middlewares.rate-limit.ratelimit.average=30\"\n  - \"traefik.http.middlewares.rate-limit.ratelimit.burst=50\"\n  \n  # Security Headers (HSTS, XSS Protection, Frame Options)\n  - \"traefik.http.middlewares.sec-headers.headers.stsSeconds=31536000\"\n  - \"traefik.http.middlewares.sec-headers.headers.browserXssFilter=true\"\n  - \"traefik.http.middlewares.sec-headers.headers.contentTypeNosniff=true\"\n  - \"traefik.http.middlewares.sec-headers.headers.customFrameOptionsValue=SAMEORIGIN\"\n  \n  # Apply Middlewares to Router\n  - \"traefik.http.routers.whoami.middlewares=rate-limit,sec-headers\"<\/code><\/pre>\n<h2>Enabling HTTP\/3 (QUIC) Support in Traefik v3<\/h2>\n<p>Accelerate mobile connection speeds over UDP by enabling HTTP\/3 support on entrypoint <code>websecure<\/code>:<\/p>\n<pre><code>command:\n  - \"--entryPoints.websecure.address=:443\/tcp\"\n  - \"--entryPoints.websecure.http3=true\"\n  - \"--entryPoints.websecure.http3.advertisedPort=443\"\nports:\n  - \"443:443\/tcp\"\n  - \"443:443\/udp\" # Required for UDP QUIC packets<\/code><\/pre>\n<h2>Traefik Diagnostic Commands<\/h2>\n<ul>\n<li><code>docker compose logs -f traefik<\/code>: Stream live routing events and ACME certificate challenge handshakes.<\/li>\n<li><code>curl -Iv https:\/\/demo.example.com<\/code>: Inspect HTTP\/2 or HTTP\/3 negotiation headers.<\/li>\n<\/ul>\n<h2>Centralized Traefik Access Logging &amp; Metrics Export to Prometheus<\/h2>\n<p>Observability in dynamic container environments is critical. Traefik includes native metric exporters for Prometheus and OpenTelemetry. Enable Prometheus metrics in Traefik&#8217;s command directives:<\/p>\n<pre><code>command:\n  - \"--metrics.prometheus=true\"\n  - \"--metrics.prometheus.entryPoint=metrics\"\n  - \"--entryPoints.metrics.address=:8082\"\n  - \"--accesslog=true\"\n  - \"--accesslog.filepath=\/var\/log\/traefik\/access.log\"\n  - \"--accesslog.format=json\"<\/code><\/pre>\n<h2>Traefik Healthcheck &amp; Circuit Breaker Middlewares<\/h2>\n<p>Prevent cascading server failures when backend containers become unresponsive by configuring Traefik&#8217;s circuit breaker and fallback retry middlewares:<\/p>\n<pre><code>labels:\n  # Automatically trip circuit breaker if 500 error rate exceeds 20%\n  - \"traefik.http.middlewares.my-circuit-breaker.circuitbreaker.expression=NetworkErrorRatio() &gt; 0.20\"\n  - \"traefik.http.middlewares.retry-mw.retry.attempts=3\"\n  - \"traefik.http.routers.whoami.middlewares=my-circuit-breaker,retry-mw\"<\/code><\/pre>\n<h2>Traefik Production Performance Tuning &amp; Concurrency Checklist<\/h2>\n<ul>\n<li><strong>Enable TCP Fast Open:<\/strong> Accelerate initial handshakes on high-traffic microservices.<\/li>\n<li><strong>Configure Idle Connection Pools:<\/strong> Maintain warm persistent backend connections to avoid socket churn.<\/li>\n<li><strong>Automate ACME Key Backup:<\/strong> Regularly archive <code>acme.json<\/code> to secure offsite storage to prevent Let&#8217;s Encrypt rate-limit lockout during disaster recovery.<\/li>\n<\/ul>\n<div style=\"background-color: #0f172a;border-left: 4px solid #38bdf8;padding: 18px 24px;margin: 30px 0;border-radius: 8px\">\n<h3 style=\"color: #38bdf8;margin-top: 0\">Recommended Related Technical Guides<\/h3>\n<ul style=\"margin-bottom: 0;color: #cbd5e1\">\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-run-docker-docker-compose-cheap-linux-vps\/\" style=\"color: #38bdf8;text-decoration: underline\">Running Docker and Compose on Budget Linux VPS<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-setup-lightweight-kubernetes-k3s-ubuntu-vps\/\" style=\"color: #38bdf8;text-decoration: underline\">Lightweight Kubernetes (K3s) with Traefik Ingress<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-secure-linux-vps-fail2ban-ufw-ssh\/\" style=\"color: #38bdf8;text-decoration: underline\">Securing Linux Cloud VPS Infrastructure with UFW<\/a><\/li>\n<\/ul>\n<\/div>\n<div style=\"background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);color: #ffffff;padding: 28px;border-radius: 12px;margin: 35px 0;text-align: center\">\n<h3 style=\"color: #ffffff;margin-top: 0;font-size: 22px\">Deploy Docker &amp; Traefik Microservices on CpanelFree<\/h3>\n<p style=\"color: #e0f2fe;font-size: 15px;max-width: 650px;margin: 0 auto 18px auto\">Scale containerized workloads with pure NVMe storage, dedicated memory, and 100% free hosting and VPS options.<\/p>\n<p>  <a href=\"https:\/\/cpanelfree.com\/\" style=\"background-color: #ffffff;color: #0284c7;font-weight: 700;padding: 12px 28px;border-radius: 8px;text-decoration: none;display: inline-block\">Get Free Cloud Hosting Today &rarr;<\/a>\n<\/div>\n<div style=\"border-left: 4px solid #38bdf8;border-radius: 8px;padding: 20px;margin: 30px 0\">\n<h3 style=\"margin-top: 0;color: #38bdf8;font-size: 18px;display: flex;align-items: center\">\n        <span style=\"margin-right: 8px\">\ud83d\udd17<\/span> Recommended Related Technical Guides:<br \/>\n    <\/h3>\n<ul style=\"margin: 10px 0 0 0;padding-left: 20px;line-height: 1.8\">\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-host-website-free-forever-guide\/\" style=\"color: #38bdf8;text-decoration: none;font-weight: 600\">How to Host a Website for Free Forever: Complete Beginner Guide (2026)<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/free-wordpress-hosting-softaculous-installer\/\" style=\"color: #38bdf8;text-decoration: none;font-weight: 600\">Top 5 Free WordPress Hosting Services with 1-Click Softaculous Installer<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-backup-linux-vps-to-cloud-storage-s3-rclone\/\" style=\"color: #38bdf8;text-decoration: none;font-weight: 600\">How to Automatically Backup Your Linux VPS to Cloud Storage (S3 \/ Rclone Guide)<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-migrate-large-wordpress-sites-without-timeouts\/\" style=\"color: #38bdf8;text-decoration: none;font-weight: 600\">How to Migrate Large WordPress Sites (Over 10GB) Without Server Timeouts<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"color: #10b981;text-decoration: none;font-weight: 600\">Explore $0 Free cPanel Web Hosting Plans (NVMe SSD, AutoSSL)<\/a><\/li>\n<\/ul>\n<\/div>\n<div style=\"background: linear-gradient(135deg, rgba(6, 182, 212, 0.15) 0%, rgba(59, 130, 246, 0.15) 100%);border-radius: 12px;padding: 25px;margin: 30px 0;text-align: center\">\n<h3 style=\"color: #38bdf8;margin-top: 0;font-size: 20px\">Deploy Fast, Reliable Web Hosting on CpanelFree<\/h3>\n<p style=\"color: #94a3b8;font-size: 14px;line-height: 1.6;max-width: 600px;margin: 0 auto 15px\">\n        Get genuine cPanel control, unmetered NVMe SSD storage, and free AutoSSL at $0 cost forever.\n    <\/p>\n<p>    <a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"display: inline-block;background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);color: #ffffff;padding: 10px 22px;border-radius: 6px;text-decoration: none;font-weight: bold;font-size: 14px\">Claim Free Hosting Account<\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Why Traefik Has Revolutionized Container Routing In traditional multi-container web architectures, deploying a new microservice behind Nginx or Apache requires manually writing a new virtual host configuration file, obtaining SSL certificates via Certbot, and reloading the web server daemon. When containers are scaled up or down frequently in Docker Compose, this manual configuration process is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2505,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[166],"tags":[],"class_list":["post-1877","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developer-stacks"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=1877"}],"version-history":[{"count":4,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1877\/revisions"}],"predecessor-version":[{"id":2305,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1877\/revisions\/2305"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/2505"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=1877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=1877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=1877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}