Use caddy with more servers based on if server is down or not

1. The problem I’m having:

I have two different servers with the same application on it and i would like to know if it is possible to set a server as primary and if that server is down it should go to anther server. But only if the first one dont answer.

2. Error messages and/or full log output:

Not applicable

3. Caddy version:

v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

I’m running windows command prompt

a. System environment:

Win10 64bit

b. Command:

caddy.exe run

c. Service/unit/compose file:

Not applicable

d. My complete Caddy config: {
	encode gzip
	reverse_proxy localhost:8096
} {
	encode gzip
	reverse_proxy localhost:5055

Really don’t want anyone to get my domain and i guess in this question it is not important?

5. Links to relevant resources:

1 Like

Yep, see the docs about load balancing: reverse_proxy (Caddyfile directive) — Caddy Documentation

You’re looking for lb_policy first. Configure multiple upstreams for reverse_proxy, and Caddy will use the first healthy one. Make sure to enable retries, and/or active/passive health checking so that Caddy can determine when the first one is down.

Would it look something like this?
And will the health check just check for a non 404 or do i need to specify any specific page or samething?

encode gzip
reverse_proxy localhost:8096{
	lb_policy       first
	health_interval 10s

Make sure to have a space before the {, this is important. Whitespace is significant in the Caddyfile.

This alone won’t enable active health checks. You need to set health_uri at least, for active health checks. The docs explain.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.