Skip to content

Commit eab8fe8

Browse files
goastlerforgetso
authored andcommitted
fix caddyfile failover (#1948)
1 parent d831c81 commit eab8fe8

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

docker/caddy

40.2 MB
Binary file not shown.

docker/provider.Caddyfile

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,49 @@
8080

8181
# reverse proxy to the provider container
8282
reverse_proxy {$CADDY_PROVIDER_CONTAINER_NAME:provider1}:{$CADDY_PROVIDER_PORT:9229} {$CADDY_PROVIDER_CONTAINER_NAME:provider2}:{$CADDY_PROVIDER_PORT2:9339} {
83+
84+
# https://caddyserver.com/docs/modules/http.handlers.reverse_proxy
85+
86+
# try A, then B, then C, etc.
8387
lb_policy first
84-
health_uri /healthz
85-
health_interval 5s
86-
health_timeout 4s
87-
fail_duration 5s
88+
89+
# how many times a backend can fail before it is considered unhealthy
8890
max_fails 1
91+
92+
# how long a backend is marked as unhealthy after it has failed (this is a non-zero duration to enable passive health checks). Passive health checks decide a backend's health based on the response code (and whether it responded at all) from normal traffic.
93+
fail_duration 1ns
94+
95+
# 5XX status codes are considered unhealthy, in addition to no response
8996
unhealthy_status 5xx
97+
98+
# long latency on response marks the backend as unhealthy
9099
unhealthy_latency 10s
91-
unhealthy_request_count 2
100+
101+
transport http {
102+
# how long to wait for a connection to be established to backend
103+
dial_timeout 1s
104+
}
105+
106+
# how long to keep trying backends before giving up
107+
lb_try_duration 5s
108+
109+
# how long to wait between retries of backends (0 doesn't work, set to 1ns for almost immediate retry)
110+
lb_try_interval 1ns
111+
112+
# example failover sequence with failing backends:
113+
# - request comes in
114+
# - lb_policy first means provider1 is tried first
115+
# - request is sent to provider1
116+
# - provider1 does not respond within 1s (dial_timeout)
117+
# - provider1 is marked as unhealthy
118+
# - request is sent to provider2
119+
# - provider2 does not respond within 1s (dial_timeout)
120+
# - in this time, provider1 is marked as healthy again (fail duration expired)
121+
# - provider2 is marked as unhealthy
122+
# - request is sent to provider1 again
123+
# - provider1 responds within 1s
124+
# - request is completed
125+
# the request is retried over all backends in turn until either it succeeds or the try_duration is reached
92126

93127
# https://caddyserver.com/docs/caddyfile/concepts#placeholders
94128
# https://caddyserver.com/docs/json/apps/http/#docs

0 commit comments

Comments
 (0)