V2: Can I fail to status code 503 instead of 502?

The http status code 503 indicates that a service is unavailable.

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:

site.example.com {
    reverse_proxy * 192.168.1.13:1133
}

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”

Does that make sense?

Hm, okay – I get what you could do in config like you’ve shown, but:

Sorry, no :frowning: That sounds like the definition of config to me. Either it’s hard-coded into Caddy or you have to configure it…

It’s something that nginx offers, in the form of:

Furthermore, it is possible to change the response code to another using the “ = response ” syntax, for example:

`error_page 404 =200 /empty.gif;

If that syntax worked with Caddy, I would expect something like this to work:

server.example.com {
    reverse_proxy * 192.168.0.13:1234
    error_page 502 =503 maintenance.html
}

or perhaps

server.example.com {
    reverse_proxy * 192.168.0.13:1234 {
        error_page 502 =503 maintentance.html
    }
}

Or some other equivalent syntax. I just want Caddy configured to never return 502 for this server, only 503.

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.