Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/traefik/traefik/llms.txt

Use this file to discover all available pages before exploring further.

Services

Defining Backend Services and Load Balancing Services define how to reach the actual backend servers that handle requests. They are part of the dynamic configuration.

HTTP Services

Load Balancer Service

The most common service type that distributes requests across multiple backend servers:
http:
  services:
    my-service:
      loadBalancer:
        servers:
          - url: "http://192.168.1.10:8080"
          - url: "http://192.168.1.11:8080"
          - url: "http://192.168.1.12:8080"
url
string
required
Backend server URL (must include scheme: http:// or https://)

Load Balancing Strategies

Weighted Round Robin (WRR)

Default strategy that distributes requests based on server weights:
http:
  services:
    weighted-service:
      loadBalancer:
        strategy: "wrr"
        servers:
          - url: "http://192.168.1.10:8080"
            weight: 3
          - url: "http://192.168.1.11:8080"
            weight: 1
With these weights, the first server receives 75% of traffic (3/4) and the second receives 25% (1/4).

Power of Two Choices (P2C)

Selects the least loaded server from two random choices:
http:
  services:
    dynamic-service:
      loadBalancer:
        strategy: "p2c"
        servers:
          - url: "http://192.168.1.10:8080"
          - url: "http://192.168.1.11:8080"
          - url: "http://192.168.1.12:8080"

Highest Random Weight (HRW)

Provides consistent hashing for sticky sessions:
http:
  services:
    consistent-service:
      loadBalancer:
        strategy: "hrw"
        servers:
          - url: "http://192.168.1.10:8080"
          - url: "http://192.168.1.11:8080"

Sticky Sessions

Maintain session affinity using cookies:
http:
  services:
    sticky-service:
      loadBalancer:
        sticky:
          cookie:
            name: "server_id"
            secure: true
            httpOnly: true
            sameSite: "lax"
        servers:
          - url: "http://192.168.1.10:8080"
          - url: "http://192.168.1.11:8080"
name
string
default:"auto-generated"
Cookie name for session affinity
secure
boolean
default:"false"
Only send cookie over HTTPS
httpOnly
boolean
default:"false"
Prevent JavaScript access to cookie
sameSite
string
default:""
SameSite policy: none, lax, or strict

Health Checks

Automatically detect and remove unhealthy servers:
http:
  services:
    monitored-service:
      loadBalancer:
        healthCheck:
          path: "/health"
          interval: "10s"
          timeout: "3s"
          scheme: "http"
          port: 8080
          hostname: "localhost"
          followRedirects: true
          headers:
            X-Health-Check: "true"
        servers:
          - url: "http://192.168.1.10:8080"
          - url: "http://192.168.1.11:8080"
path
string
required
URL path for health check endpoint
interval
duration
default:"30s"
Time between health checks
timeout
duration
default:"5s"
Maximum time to wait for health check response
scheme
string
Override server scheme for health checks
port
int
Override server port for health checks

Advanced Service Types

Weighted Round Robin Service

Load balance between multiple services:
http:
  services:
    canary-deployment:
      weighted:
        services:
          - name: stable-version
            weight: 90
          - name: canary-version
            weight: 10
    
    stable-version:
      loadBalancer:
        servers:
          - url: "http://192.168.1.10:8080"
    
    canary-version:
      loadBalancer:
        servers:
          - url: "http://192.168.1.20:8080"

Mirroring Service

Mirror traffic to a second service for testing:
http:
  services:
    mirrored:
      mirroring:
        service: production
        mirrorBody: true
        maxBodySize: 1048576  # 1MB
        mirrors:
          - name: testing
            percent: 10
    
    production:
      loadBalancer:
        servers:
          - url: "http://192.168.1.10:8080"
    
    testing:
      loadBalancer:
        servers:
          - url: "http://192.168.1.20:8080"
Mirroring only copies requests to the mirror service. Responses from mirrors are discarded.

Failover Service

Automatically switch to fallback when main service fails:
http:
  services:
    resilient:
      failover:
        service: primary
        fallback: backup
    
    primary:
      loadBalancer:
        healthCheck:
          path: "/health"
          interval: "10s"
        servers:
          - url: "http://192.168.1.10:8080"
    
    backup:
      loadBalancer:
        servers:
          - url: "http://192.168.1.20:8080"

TCP Services

Configure TCP backend services:
tcp:
  services:
    database:
      loadBalancer:
        servers:
          - address: "192.168.1.10:5432"
          - address: "192.168.1.11:5432"
TCP services use address (IP:Port) instead of url like HTTP services.

Complete Example

http:
  services:
    # Production service with health checks
    production-api:
      loadBalancer:
        strategy: "p2c"
        passHostHeader: true
        sticky:
          cookie:
            name: "api_server"
            secure: true
            httpOnly: true
        healthCheck:
          path: "/health"
          interval: "10s"
          timeout: "3s"
          headers:
            Authorization: "Bearer health-check-token"
        servers:
          - url: "http://192.168.1.10:8080"
            weight: 2
          - url: "http://192.168.1.11:8080"
            weight: 2
          - url: "http://192.168.1.12:8080"
            weight: 1
    
    # Canary deployment
    canary:
      weighted:
        sticky:
          cookie:
            name: "version"
        services:
          - name: production-api
            weight: 95
          - name: beta-api
            weight: 5
    
    beta-api:
      loadBalancer:
        healthCheck:
          path: "/health"
          interval: "10s"
        servers:
          - url: "http://192.168.1.20:8080"
    
    # Mirrored for testing
    mirrored-api:
      mirroring:
        service: production-api
        maxBodySize: 2097152  # 2MB
        mirrors:
          - name: staging-api
            percent: 10
    
    staging-api:
      loadBalancer:
        servers:
          - url: "http://192.168.1.30:8080"