Find Your Perfect Server AI-powered · Instant results

IN AFRICA

ALBANIA

ARGENTINA

AUSTRALIA

AUSTRIA

AZERBAIJAN

B AND H

BANGLADESH

BELGIUM

BRAZIL

BULGARIA

CANADA

CHILE

CHINA

COLOMBIA

COSTA RICA

CROATIA

CYPRUS

CZECH

DENMARK

ECUADOR

EGYPT

EL SALVADOR

ESTONIA

FINLAND

FOR BACKUP AND STORAGE

FOR DATABASE

FOR EMAIL

FOR MEDIA STREAMING

FRANCE

GEORGIA

GERMANY

GREECE

GUATEMALA

HUNGARY

ICELAND

IN ASIA

IN EUROPE

IN NORTH AMERICA

IN SOUTH AMERICA

INDIA

INDONESIA

IRELAND

ISRAEL

ITALY

JAPAN

KAZAKHSTAN

KENYA

KOSOVO

LATVIA

LIBYA

LITHUANIA

LUXEMBOURG

MALAYSIA

MALTA

MEXICO

MOLDOVA

MONTENEGRO

MOROCCO

NETHERLANDS

NEW ZEALAND

NIGERIA

NORWAY

PAKISTAN

PANAMA

PARAGUAY

PERU

PHILIPPINES

POLAND

PORTUGAL

QATAR

ROMANIA

RUSSIA

SAUDI ARABIA

SERBIA

SINGAPORE

SLOVAKIA

SLOVENIA

SOUTH AFRICA

SOUTH KOREA

SPAIN

SWEDEN

SWITZERLAND

TAIWAN

THAILAND

TUNISIA

TURKEY

UK

UKRAINE

UNITED ARAB EMIRATES

URUGUAY

USA

UZBEKISTAN

VIETNAM

IN OCEANIA

Configure Traefik v3 Reverse Proxy with Let's Encrypt on Bare Metal

A complete, production-grade guide to deploying Traefik v3 as an automated edge reverse proxy on bare-metal Linux. Learn how to configure static and dynamic routing, automate Let's Encrypt wildcard SSL certificates, dynamically discover Docker containers, and lock down the dashboard with BasicAuth and IP allowlisting.

Configure Traefik v3 Reverse Proxy with Let's Encrypt on Bare Metal

Managing dozens of self-hosted web applications, APIs, and microservices on a bare-metal dedicated server using traditional Nginx or Apache setups quickly becomes tedious—requiring manual virtual host edits, certificate renewal scripts, and service reloads every time you spin up a new container. Traefik v3 solves this bottleneck by acting as a cloud-native, dynamic edge router that integrates directly with the Docker socket and local configuration files. When a new service starts, Traefik automatically detects its labels, provisions a valid TLS certificate via Let's Encrypt, and routes incoming HTTPS traffic without dropping a single packet. This guide walks through architecting a hardened Traefik v3 deployment on bare-metal Ubuntu, complete with zero-touch wildcard SSL via DNS-01 challenges, security headers, and multi-layered dashboard protection.

What You'll Learn

Prerequisites & Network Architecture

Before beginning the deployment, ensure your bare-metal environment meets these requirements:

  • Operating System: Clean installation of Ubuntu 24.04 LTS or Ubuntu 22.04 LTS (64-bit) with root or sudo access.

  • Container Runtime: Docker Engine and the Docker Compose plugin (docker compose) installed. (If you have not containerized your host yet, follow our Bare Metal Containerization guide first.)

  • Domain & DNS Control: A registered domain name (e.g., yourdomain.com) with A records for @ and * (wildcard) pointing to your bare-metal server's public IPv4 address.

  • DNS Provider API Token: For zero-touch wildcard SSL certificates (*.yourdomain.com), you will need an API token from a supported DNS provider such as Cloudflare, DigitalOcean, Route53, or Namecheap.

  • Open Network Ports: TCP ports 80 (HTTP) and 443 (HTTPS) reachable from the public internet.

If you are provisioning new infrastructure to host high-throughput microservices, APIs, or multi-tenant web applications, explore iDatam's bare-metal dedicated servers featuring unmetered 1 Gbps+ uplinks and full root control.

Step 1: System Preparation & Creating an Isolated Docker Network

  1. Start by updating your system packages and installing apache2-utils (used later to generate bcrypt password hashes for dashboard authentication):

    Bash
    
    sudo apt update && sudo apt upgrade -y
    sudo apt install -y apache2-utils curl ufw
                                            
  2. Create a dedicated directory hierarchy under /opt/traefik to separate static configuration, dynamic routing rules, and persistent SSL certificate storage:

    Bash
    
    sudo mkdir -p /opt/traefik/{config,certs}
                                            
  3. Create an empty acme.json file to store Let's Encrypt private keys and certificates, and lock its permissions to 600. Traefik will refuse to start or issue certificates if acme.json has overly permissive read/write flags:

    Bash
    
    sudo touch /opt/traefik/certs/acme.json
    sudo chmod 600 /opt/traefik/certs/acme.json
                                            
  4. Next, create an external Docker bridge network named proxy. All web-facing containers across different Docker Compose stacks will attach to this shared network so Traefik can route traffic to them internally without exposing backend container ports to the host:

    Bash
    
    sudo docker network create proxy
                                            

    Verification: Confirm the network exists by running sudo docker network ls | grep proxy.

Step 2: Configuring Static Entrypoints & Let's Encrypt Resolvers (traefik.yml)

Traefik splits its configuration into two layers:

  1. Static Configuration (traefik.yml): Loaded once at startup. Defines entrypoints (ports), providers (Docker, local files), logging, and SSL certificate resolvers.

  2. Dynamic Configuration (dynamic.yml): Hot-reloaded automatically whenever edited. Defines routers, middlewares, TLS ciphers, and external service backends.

Bash

sudo nano /opt/traefik/config/traefik.yml
                                
YAML

global:
  checkNewVersion: false
  sendAnonymousUsage: false

api:
  dashboard: true
  insecure: false

entryPoints:
  web:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
          permanent: true

  websecure:
    address: ":443"
    asDefault: true
    http:
      tls:
        certResolver: letsencrypt
        domains:
          - main: "yourdomain.com"
            sans:
              - "*.yourdomain.com"

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
    network: proxy

  file:
    filename: "/etc/traefik/dynamic.yml"
    watch: true

certificatesResolvers:
  letsencrypt:
    acme:
      email: "admin@yourdomain.com"
      storage: "/certs/acme.json"
      caServer: "https://acme-v02.api.letsencrypt.org/directory"
      dnsChallenge:
        provider: cloudflare
        delayBeforeCheck: 10
        resolvers:
          - "1.1.1.1:53"
          - "8.8.8.8:53"

log:
  level: INFO
                                

Key Configuration Breakdown

  • insecure: false: Ensures the Traefik dashboard is never exposed over an unencrypted HTTP port (:8080). Instead, it must be routed securely through websecure (:443).

  • Global HTTP-to-HTTPS Redirection: Every request arriving on port 80 (web) is automatically upgraded to 443 (websecure) with a 301 permanent redirect.

  • exposedByDefault: false: Prevents Traefik from accidentally exposing internal backend databases (like Redis or PostgreSQL containers) to the public internet unless explicitly opted in via traefik.enable=true.

  • dnsChallenge: Uses your DNS provider's API (Cloudflare shown above) to validate domain ownership via TXT records. This enables wildcard certificates (*.yourdomain.com) and works even if your server sits behind strict firewall rules.

Alternative HTTP-01 Challenge: If your DNS provider does not support API-driven DNS challenges, replace the entire dnsChallenge block with:

YAML

httpChallenge:
  entryPoint: web
                                

(Note: HTTP-01 issues individual certificates per subdomain rather than a single wildcard certificate.)

Step 3: Setting Up Dynamic Middlewares & Security Headers (dynamic.yml)

Create the dynamic configuration file to define reusable security middlewares, modern TLS cipher suites, IP allowlists, and dashboard routing:

Bash

sudo nano /opt/traefik/config/dynamic.yml
                                

Paste the following configuration, replacing YOUR_ADMIN_PUBLIC_IP with your static office or home IP address:

YAML

tls:
  options:
    default:
      minVersion: VersionTLS12
      sniStrict: true
      cipherSuites:
        - TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
        - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
        - TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
        - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
        - TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
        - TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305

http:
  middlewares:
    # 1. Security Headers (HSTS, XSS, Frame Protection)
    sec-headers:
      headers:
        browserXssFilter: true
        contentTypeNosniff: true
        frameDeny: true
        stsIncludeSubdomains: true
        stsPreload: true
        stsSeconds: 31536000
        customResponseHeaders:
          X-Robots-Tag: "none,noarchive,nosnippet,notranslate,noimageindex"
          server: ""

    # 2. IP Allowlist for Sensitive Admin Panels
    admin-ip-allowlist:
      ipAllowList:
        sourceRange:
          - "127.0.0.1/32"
          - "YOUR_ADMIN_PUBLIC_IP/32"

    # 3. BasicAuth Credentials for Traefik Dashboard
    dashboard-auth:
      basicAuth:
        usersFile: "/etc/traefik/.htpasswd"

    # 4. Rate Limiting to Mitigate Brute-Force & Scrapers
    rate-limit:
      rateLimit:
        average: 100
        burst: 50

  routers:
    # Securely Route Traefik Dashboard to https://traefik.yourdomain.com
    traefik-dashboard:
      rule: "Host(`traefik.yourdomain.com`)"
      entryPoints:
        - websecure
      service: api@internal
      middlewares:
        - sec-headers
        - admin-ip-allowlist
        - dashboard-auth
      tls:
        certResolver: letsencrypt
                                

Why Layer ipAllowList and basicAuth? By chaining admin-ip-allowlist and dashboard-auth on the traefik-dashboard router, unauthorized visitors outside your trusted IP range receive an immediate 403 Forbidden response before even reaching the authentication prompt—completely neutralizing brute-force attacks against your edge router. (If you travel frequently without a static IP, remove admin-ip-allowlist from the router's middleware list and rely on dashboard-auth + rate-limit.)

Step 4: Generating BasicAuth Credentials & Environment Secrets

  1. Generate an encrypted password file using htpasswd (bcrypt hashing via -B) for your dashboard administrator user:

    Bash
    
    sudo htpasswd -cB /opt/traefik/config/.htpasswd admin
    sudo chmod 600 /opt/traefik/config/.htpasswd
                                            

    Enter and confirm a strong password when prompted.

  2. Next, create a .env file inside /opt/traefik to store your DNS provider API credentials securely outside of version-controlled YAML files:

    Bash
    
    sudo nano /opt/traefik/.env
                                            
    Env
    
    CF_DNS_API_TOKEN=your_cloudflare_zone_dns_edit_token_here
                                            
    Bash
    
    sudo chmod 600 /opt/traefik/.env
                                            

Step 5: Deploying Traefik v3 via Docker Compose

Create the docker-compose.yml manifest inside /opt/traefik:

Bash

sudo nano /opt/traefik/docker-compose.yml
                                
YAML

services:
  traefik:
    image: traefik:v3.2
    container_name: traefik
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    env_file:
      - .env
    ports:
      - "80:80"
      - "443:443"
    networks:
      - proxy
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./config/traefik.yml:/etc/traefik/traefik.yml:ro
      - ./config/dynamic.yml:/etc/traefik/dynamic.yml:ro
      - ./config/.htpasswd:/etc/traefik/.htpasswd:ro
      - ./certs/acme.json:/certs/acme.json

networks:
  proxy:
    external: true
                                

Launch Traefik in detached mode and inspect the container logs to verify that Traefik initialized cleanly and provisioned your Let's Encrypt wildcard certificate:

Bash

cd /opt/traefik
sudo docker compose up -d
sudo docker logs -f traefik
                                

Verification: Wait 15–30 seconds for the DNS-01 TXT record propagation. Once complete, navigate to https://traefik.yourdomain.com in your browser, enter your admin credentials, and confirm the Traefik v3 dashboard loads with a valid padlock icon.

Step 6: Routing a Backend Container with Automatic HTTPS

To verify zero-touch container discovery, deploy a lightweight whoami diagnostic microservice attached to the proxy network.

Bash

sudo mkdir -p /opt/apps/whoami
sudo nano /opt/apps/whoami/docker-compose.yml
                                
YAML

services:
  whoami:
    image: traefik/whoami:latest
    container_name: whoami
    restart: unless-stopped
    networks:
      - proxy
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`whoami.yourdomain.com`)"
      - "traefik.http.routers.whoami.entrypoints=websecure"
      - "traefik.http.routers.whoami.tls=true"
      - "traefik.http.routers.whoami.middlewares=sec-headers@file,rate-limit@file"
      - "traefik.http.services.whoami.loadbalancer.server.port=80"

networks:
  proxy:
    external: true
                                
Bash

cd /opt/apps/whoami
sudo docker compose up -d
                                

Notice that no host ports (8080:80) are published on the whoami container. Traefik detects the container via its Docker labels, applies the sec-headers and rate-limit middlewares defined in dynamic.yml, and immediately serves https://whoami.yourdomain.com over TLS.

Step 7: Routing Non-Docker Bare-Metal Services via File Provider

On a dedicated server, you may also run native systemd services directly on the host (such as a Prometheus metrics endpoint, a Node.js API, or a game control panel) alongside Docker containers. You can route HTTPS traffic to native host services using Traefik's file provider without containerizing them.

Bash

sudo nano /opt/traefik/config/dynamic.yml
                                
YAML

http:
  routers:
    native-app:
      rule: "Host(`status.yourdomain.com`)"
      entryPoints:
        - websecure
      service: native-app-service
      middlewares:
        - sec-headers
      tls:
        certResolver: letsencrypt

  services:
    native-app-service:
      loadBalancer:
        servers:
          - url: "http://172.17.0.1:9090"
                                

Because watch: true is enabled in traefik.yml, Traefik applies the route within seconds—no container restart or downtime required.

Step 8: Hardening Docker Socket Access & Firewall Rules

1. Restricting Public Ports with UFW

Ensure that only SSH, HTTP, and HTTPS are exposed to the public internet on your bare-metal server:

Bash

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp comment 'SSH Access'
sudo ufw allow 80/tcp comment 'Traefik HTTP Redirect'
sudo ufw allow 443/tcp comment 'Traefik HTTPS Edge'
sudo ufw enable
                                

Docker & UFW Warning: By default, Docker manipulates iptables directly and can bypass UFW rules if you accidentally map ports: - "8080:80" on a backend container. Always use expose: or omit ports: entirely on backend containers connected to the proxy network so traffic must pass through Traefik.

2. Optional: Isolating the Docker Socket with docker-socket-proxy

Mounting /var/run/docker.sock directly into Traefik grants read-only access to the Docker daemon API. For maximum multi-tenant isolation, deploy Tecnativa's docker-socket-proxy inside /opt/traefik/docker-compose.yml to filter API calls strictly to container and network metadata:

YAML

services:
  socket-proxy:
    image: tecnativa/docker-socket-proxy:latest
    container_name: socket-proxy
    restart: unless-stopped
    privileged: true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      CONTAINERS: 1
      NETWORKS: 1
      SERVICES: 1
      TASKS: 1
      POST: 0
    networks:
      - socket-net
                                

Update endpoint: "tcp://socket-proxy:2375" inside traefik.yml and remove the direct /var/run/docker.sock volume mount from the traefik container.

Troubleshooting Common Traefik v3 Issues

  • Browser Displays TRAEFIK DEFAULT CERT (Self-Signed Warning):

    • Let's Encrypt rate-limited your domain or failed the DNS-01/HTTP-01 challenge. Check live ACME errors with sudo docker logs traefik | grep -i acme.

    • Verify /opt/traefik/certs/acme.json has 600 permissions (ls -la /opt/traefik/certs/acme.json) and that your API token in .env has Zone:DNS:Edit privileges.

  • 404 Page Not Found on a Newly Deployed Container:

    • Confirm the container is attached to the proxy network (sudo docker inspect <container_name> | grep -A 10 Networks). If a container belongs to multiple Docker networks, add the label "traefik.docker.network=proxy" explicitly.

  • 502 Bad Gateway Error:

    • Traefik reached the container, but the internal application port is mismatched. Verify the internal listening port of your app and set "traefik.http.services.<name>.loadbalancer.server.port=<INTERNAL_PORT>".

Frequently Asked Questions

Why does the browser display TRAEFIK DEFAULT CERT instead of a Let's Encrypt certificate?

Let's Encrypt may have rate-limited your domain or failed the DNS-01/HTTP-01 challenge. Check live ACME errors with sudo docker logs traefik | grep -i acme, ensure /opt/traefik/certs/acme.json has 600 permissions, and verify your API token in .env has Zone:DNS:Edit privileges.

Why do I get a 404 Page Not Found on a newly deployed container?

Confirm the container is attached to the proxy network using sudo docker inspect <container_name> | grep -A 10 Networks. If the container belongs to multiple Docker networks, add the "traefik.docker.network=proxy" label explicitly.

What causes a 502 Bad Gateway error in Traefik v3?

Traefik reached the container, but the internal application port is mismatched. Verify the internal listening port of your application and set "traefik.http.services.<name>.loadbalancer.server.port=<INTERNAL_PORT>".

Why chain ipAllowList and basicAuth on the Traefik dashboard?

Chaining admin-ip-allowlist and dashboard-auth returns an immediate 403 Forbidden response to unauthorized IPs before reaching the authentication prompt, helping block brute-force attempts against the edge router.

Discover iDatam Dedicated Server Locations

iDatam servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.

Up