Traefik后端备份服务器配置咨询及v1.6版本weight=0实现疑问
Hey there! Let's break down your questions about Traefik 1.6 and backup backend functionality one by one.
1. Simulating Nginx/HAProxy-style "Backup" Backends
Traefik 1.6 doesn't have a native backup flag like Nginx or HAProxy, but you can replicate this failover behavior using two reliable approaches:
Option 1: Priority + Circuit Breakers
This is the most straightforward method to mimic backup server behavior:
- Assign a higher priority to your primary backend servers (e.g.,
priority=10) and a lower priority to your backup server (e.g.,priority=1). - Configure a circuit breaker for the primary backend. When the primary backend's health check failure rate hits your threshold, the circuit breaker triggers, and traffic automatically falls back to the lower-priority backup.
Here's a sample configuration using the file provider:
[backends] # Primary backend with higher priority [backends.main] [backends.main.servers.server1] url = "http://main-server-1:80" [backends.main.servers.server2] url = "http://main-server-2:80" # Circuit breaker: Trigger if >50% of requests result in network errors [backends.main.circuitbreaker] expression = "NetworkErrorRatio() > 0.5" priority = 10 # Backup backend with lower priority [backends.backup] [backends.backup.servers.backup1] url = "http://backup-server:80" priority = 1 [frontends] [frontends.myapp] # List both backends; Traefik uses priority to handle failover backend = "main,backup" passHostHeader = true [frontends.myapp.routes.test_1] rule = "Host:myapp.example.com"
Option 2: Health Checks + Routing Rules
You can also tie routing rules to backend health status, but this requires more complex setup (like integrating external monitoring to update Traefik configs dynamically). For most use cases, the priority + circuit breaker approach is simpler and more reliable.
2. Weight=0 Behavior in Traefik 1.6
In Traefik 1.6, setting weight=0 on a server completely excludes it from the load balancing pool—even if all other servers are unavailable.
Weight values control traffic distribution ratios between healthy servers, and a weight of 0 means no traffic will ever be routed to that server, regardless of the health of other backends. If you want a server to act as a fallback, weight=0 isn't the right choice; stick with the priority + circuit breaker method instead.
内容的提问来源于stack exchange,提问作者user1788784

