Basic questions for reverse proxy health status / body

1. Output of caddy version:

v2.5.2 h1:eCJdLyEyAGzuQTa5Mh3gETnYWDClo1LjtQm2q9RNZrs=

2. How I run Caddy:

a. System environment:

Ubuntu 20.04.4 LTS

b. Command:


c. Service/unit/compose file:


d. My complete Caddy config:

        # Enable Debug mode
        # debug

        # Disable admin API
        admin off

poc1.domain {
        header {
                # Hide "Server: Caddy"


        log {
                output file /var/log/caddy/poc1.domain-error.log
                format console

        reverse_proxy * {
                to poc01-backend:9392

		lb_policy cookie
		lb_try_duration 5s
		lb_try_interval 250ms
		fail_duration 30s

		health_uri     /status # Backend health check path
		health_interval 10s
		health_timeout  2s
		#health_body	^(.(?!ERROR).)*$
		#health_status   200

        handle_errors {
                @404-410 expression `{err.status_code} in [404, 410]`
                handle @404-410 {
                        rewrite * 404.html
                        root * /usr/share/caddy

                @5xx expression `{err.status_code} >= 500 && {err.status_code} < 600`
                handle @5xx {
                        rewrite * maintenance.html
                        root * /usr/share/caddy

                handle {
                        respond "It's another error"

3. The problem I’m having:

i’m having two questions where i can’t figure out on how to properly configure some rather basic configurations.

health body regex => our statuspage (stupidly) returns a 200 and contains an error message in the body.
how does a regex for caddy have to look, that checks the return body for the content “ERROR”?

health status range => our backend returns statuscodes in the 300 range for some bootup / config stages, so we need to configure the health status to range from 2xx to 3xx, so we can check them on start.
how do i properly configure this? :slight_smile:

4. Error messages and/or full log output:


5. What I already tried:

Playing around with the config above, always bumping into something wrongly formatted / config errors.

6. Links to relevant resources:

Why are you disabling the admin API?

If you do, you won’t be able to reload Caddy (for graceful config changes) so you’ll have to restart the whole process which can cause downtime.

There’s no benefit to removing this header. It doesn’t hide anything that people couldn’t otherwise figure out about your server.

If you only have a single backend, I don’t think you’ll really get any benefit from enabling load balancing or health check features. It only becomes useful if you have multiple upstreams configured, where if one goes down, another could pick up the slack.

That said, you can play around with with the Golang flavor to craft the regexp you need.

Unfortunately, we don’t currently support ranges with a different first number. You can only do 2xx or 3xx but not both.

Wouldn’t it make the most sense to just match on 2xx though, since 3xx means it’s still booting up? If it’s booting up, that means it’s not ready yet, so marking it as healthy doesn’t seem correct.

1 Like

Hi Francis,
thanks for your reply :slight_smile:

admin off => this is a remnant of some experiments we did. i removed it from our automation and it will be gone with the next config update

-server => same thing. we played around with the configs and forgot to remove this (since it doesn’t hurt :smiley: )

upstreams => copy paste error on my end. we have 2-5 backend nodes behind each caddy. so it makes sense since we actually want to load balance. i’ll play around with the page you suggested.

health status => i had hoped to be able to build a workaround with an expression or something similar.
we actually get some boot up information (down to specific error messages) on the web frontend of our applications, which makes starting issues easier to diagnose than digging through the log files.

since we can freely adjust our DNS entries, i might set up something like maintenance.domain which checks for health status 300 - so we get some sort of workaround that way.

thank you very much for the fast reply :saluting_face:

Edit: Another idea we thought about is removing the health_status completly and simply going with the health_body regex for now

1 Like

Yeah, you probably don’t need both.

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