2

I'm using caddy for dynamic ssl. I am using the reverse_proxy header and now I want to return a custom 404 response when the reverse_proxy returns a 404.

Is it possible? I looked at handle_erros directive but looks like it doesn't work with reverse_proxy. Here's a statement from the caddy doc.

Note that certain directives, for example, reverse_proxy which may write a response with an HTTP status which is classified as an error, will not trigger the error routes.

Is there a way to achieve what I want?

Reyansh Kharga
  • 356
  • 5
  • 18

1 Answers1

1

This is an old question but I bumped the same issue today and fixed by using below config

reverse_proxy localhost:3000 {
    @error status 500 404
    handle_response @error {
        root    * /path/to/error/pages
        rewrite * /{rp.status_code}.html
        file_server
    }
}

Source: https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#examples

k4mrul
  • 36
  • 1
  • 1
  • 5