I’m trying to set up a proxy with two upstreams, and I want caddy to try the next upstream if the first one it tried answered with a non 2XX status code
Essentially I don’t know which server will be able to fulfill a given request ahead of time so I want to try both and return whichever is successful.
This only gives me one of the upstreams at random and lets errors pass through. I’d like the behaviour of status_check but on every request. Is this possible?
Caddy’s proxy middleware handles errors only for hosts that fail to return a response (i.e. when a net.Dial() call fails or if the body the backend server returns is too large). This is a known issue, see https://github.com/mholt/caddy/issues/753.
Theoretically you could health_check every second, but only on the same path each time, there’s no way to make it do health checks per request for that request path.
Having a proxy “fork” the request to two upstreams simultaneously, and return content from whichever one returns a 2xx result first, is pretty advanced logic and beyond the current scope of proxy and the Caddyfile.
I’m not even sure if you could do that with something like HAProxy.