NewCode CLOUD — 20% off your first month on all cloud VPSClaim

How to Set Up Traefik on Hong Kong VPS: Modern Reverse Proxy for Docker (2026)

· 3 min read

Traefik is a cloud-native reverse proxy that integrates directly with Docker — it automatically discovers your containers, routes traffic to them, and issues Let’s Encrypt SSL certificates without manual Nginx configuration. On a Hong Kong VPS running multiple Docker services, Traefik eliminates the config-file overhead of managing Nginx virtual hosts per service: add a Docker label, and Traefik handles the rest.


Traefik vs Nginx: When to Choose Each

Scenario Traefik Nginx
Multiple Docker services on one VPS ✓ Auto-discovers containers Manual config per service
Frequent service deployments ✓ Zero-config routing via labels Reload required per change
SSL per service, many domains ✓ Automatic Let’s Encrypt per container Manual certbot per domain
Non-Docker (bare PHP/Node.js) Possible but awkward ✓ Native and simpler
Fine-grained static file tuning Limited ✓ Better control

Step 1: Install Docker and Create Network

apt update && apt upgrade -y
curl -fsSL https://get.docker.com | sh
systemctl enable --now docker

# Create a shared Docker network — all services Traefik proxies must join it
docker network create traefik-public

ufw allow 80/tcp && ufw allow 443/tcp && ufw enable

Step 2: Deploy Traefik

mkdir -p /opt/traefik && cd /opt/traefik

# Create Let's Encrypt storage file
touch acme.json && chmod 600 acme.json

cat > docker-compose.yml << 'EOF'
version: '3.8'

services:
  traefik:
    image: traefik:v3.0
    container_name: traefik
    restart: unless-stopped
    command:
      # API and dashboard
      - --api.dashboard=true
      - --api.insecure=false

      # Docker provider — auto-discover containers
      - --providers.docker=true
      - --providers.docker.exposedByDefault=false
      - --providers.docker.network=traefik-public

      # Entrypoints
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443

      # Redirect all HTTP to HTTPS
      - --entrypoints.web.http.redirections.entrypoint.to=websecure
      - --entrypoints.web.http.redirections.entrypoint.scheme=https

      # Let's Encrypt via TLS challenge
      - --certificatesresolvers.letsencrypt.acme.email=admin@yourdomain.com
      - --certificatesresolvers.letsencrypt.acme.storage=/acme.json
      - --certificatesresolvers.letsencrypt.acme.tlschallenge=true

      # Logging
      - --log.level=INFO
      - --accesslog=true

    ports:
      - "80:80"
      - "443:443"

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./acme.json:/acme.json

    networks:
      - traefik-public

    labels:
      - "traefik.enable=true"
      # Secure dashboard — accessible at dashboard.yourdomain.com
      - "traefik.http.routers.dashboard.rule=Host(`dashboard.yourdomain.com`)"
      - "traefik.http.routers.dashboard.entrypoints=websecure"
      - "traefik.http.routers.dashboard.tls.certresolver=letsencrypt"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.routers.dashboard.middlewares=auth"
      # Basic auth for dashboard (generate with: htpasswd -nb admin password)
      - "traefik.http.middlewares.auth.basicauth.users=admin:$$apr1$$HASH$$"

networks:
  traefik-public:
    external: true
EOF

docker compose up -d
docker compose logs -f traefik

Step 3: Deploy Services with Traefik Labels

Any Docker container gets automatic SSL routing by adding Traefik labels:

Example: WordPress

cat > /opt/wordpress/docker-compose.yml << 'EOF'
version: '3.8'

services:
  wordpress:
    image: wordpress:6.5-php8.3-fpm-alpine
    restart: unless-stopped
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: WPPassword!
    volumes:
      - wp_data:/var/www/html
    networks:
      - traefik-public
      - internal
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.wordpress.rule=Host(`blog.yourdomain.com`)"
      - "traefik.http.routers.wordpress.entrypoints=websecure"
      - "traefik.http.routers.wordpress.tls.certresolver=letsencrypt"
      - "traefik.http.services.wordpress.loadbalancer.server.port=80"

  db:
    image: mysql:8.0
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wpuser
      MYSQL_PASSWORD: WPPassword!
      MYSQL_ROOT_PASSWORD: RootPassword!
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - internal

volumes:
  wp_data:
  db_data:

networks:
  traefik-public:
    external: true
  internal:
EOF

docker compose up -d

Traefik detects the new container within seconds, issues a Let’s Encrypt certificate for blog.yourdomain.com, and begins routing traffic — no config file editing, no reload.

Example: Node.js API

services:
  api:
    image: your-registry/myapi:latest
    restart: unless-stopped
    networks:
      - traefik-public
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api.rule=Host(`api.yourdomain.com`)"
      - "traefik.http.routers.api.entrypoints=websecure"
      - "traefik.http.routers.api.tls.certresolver=letsencrypt"
      - "traefik.http.services.api.loadbalancer.server.port=3000"
      # Rate limiting middleware
      - "traefik.http.routers.api.middlewares=api-ratelimit"
      - "traefik.http.middlewares.api-ratelimit.ratelimit.average=100"
      - "traefik.http.middlewares.api-ratelimit.ratelimit.burst=50"

Step 4: Useful Traefik Middlewares

Security Headers

# In Traefik static config or as Docker labels:
- "traefik.http.middlewares.security-headers.headers.stsSeconds=31536000"
- "traefik.http.middlewares.security-headers.headers.stsIncludeSubdomains=true"
- "traefik.http.middlewares.security-headers.headers.contentTypeNosniff=true"
- "traefik.http.middlewares.security-headers.headers.browserXssFilter=true"
- "traefik.http.middlewares.security-headers.headers.frameDeny=true"

# Apply to a router:
- "traefik.http.routers.myapp.middlewares=security-headers"

IP Allowlist (Restrict Admin Panels)

<code">- "traefik.http.middlewares.admin-ip.ipallowlist.sourcerange=YOUR_OFFICE_IP/32,10.0.0.0/8"
- "traefik.http.routers.admin.middlewares=admin-ip,auth"

Compress Responses

<code">- "traefik.http.middlewares.compress.compress=true"
- "traefik.http.routers.myapp.middlewares=compress,security-headers"

Circuit Breaker

<code">- "traefik.http.middlewares.circuit-breaker.circuitbreaker.expression=ResponseCodeRatio(500, 600, 0, 600) > 0.30"

Step 5: Dynamic Configuration File

For non-Docker services (external APIs, bare-metal backends), use a dynamic config file:

<code">mkdir -p /opt/traefik/dynamic

cat > /opt/traefik/dynamic/external.yml << 'EOF'
http:
  routers:
    legacy-app:
      rule: "Host(`legacy.yourdomain.com`)"
      entrypoints:
        - websecure
      tls:
        certResolver: letsencrypt
      service: legacy-backend

  services:
    legacy-backend:
      loadBalancer:
        servers:
          - url: "http://192.168.1.50:8080"
        healthCheck:
          path: /health
          interval: 10s
          timeout: 3s
EOF

Add the dynamic file provider to your Traefik command:

<code">- --providers.file.directory=/dynamic
- --providers.file.watch=true

Step 6: Monitor Traefik

<code"># View real-time request logs
docker logs -f traefik

# Check router and service status via API
curl http://localhost:8080/api/http/routers | python3 -m json.tool

# Access the dashboard at https://dashboard.yourdomain.com
# Shows all active routers, services, middlewares, and certificates

Traefik also exposes Prometheus metrics — add --metrics.prometheus=true and scrape from your Grafana stack for request rate, error rate, and latency dashboards.


Conclusion

Traefik on a Hong Kong VPS transforms multi-service Docker deployments — zero manual SSL configuration, automatic container discovery, and middleware-based rate limiting and security headers applied with Docker labels. For VPS environments running 5+ Docker services with frequent deployments, Traefik’s operational simplicity outweighs Nginx’s fine-grained static-file performance advantages.

Run your stack: Browse Server.HK Hong Kong VPS plans — a 4 GB VPS handles Traefik plus 5–10 Docker services with CN2 GIA routing for all of them.

Related articles

More in VPS & ServersServer setup guides