I’m trying to use Caddy to reverse_proxy to a service that may or may not be available. Right now if the service goes away I get a 502 bad gateway, which is technically valid, but not really what I want to return in that case.
Aside from manually changing the config, is there anything that I can do to automatically have Caddy return 503 instead of 502? My current redirect is super simple:
Do you mean that you want Caddy’s code to be changed to return 503 so that your config doesn’t have to, i.e. so your config above will return a 503 instead of 502? Just trying to understand what you want here.
I can manually (or use a program to) change my config and update it to something like
site.example.com {
respond * 503
}
(or use the API)
But it would be nicer if I didn’t have to do anything and I could tell Caddy “instead of returning 502, return 503. Otherwise just do what you would normally do”
Okay, so, to clarify: that does require configuration, and that’s how it works for nginx too then. There’s no way to make it happen “aside from manually changing the config.”
With that cleared up, then yes, this is possible I think using a CEL matcher, but one of the goals for 2.1 is to make error handling a little more straightforward and customizable in the Caddyfile than having to use CEL.
To bring more closure to the issue, you can alternatively change the response in the reverse_proxy module itself as of Caddy 2.1: Modules - Caddy Documentation