Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to override error_pages of reverse_proxy? #4382

Closed
JaneX8 opened this issue Oct 14, 2021 · 1 comment
Closed

How to override error_pages of reverse_proxy? #4382

JaneX8 opened this issue Oct 14, 2021 · 1 comment
Labels
question ❔ Help is being requested

Comments

@JaneX8
Copy link

JaneX8 commented Oct 14, 2021

How do I override the error_handling hwen using a reverse_proxy? I have this for example in my Caddyfile:

(errorpages) {
    handle_errors {
        @404 {
            expression {http.error.status_code} == 404
        }
        rewrite @404 /site/404.html
        file_server
    }
}

home.local {
  import errorpages
  reverse_proxy http://home:8080
}

I want to be able to force a custom 404.html, so I can include the same snippet in all proxied sites, resulting in a custom error response nomatter what application if proxied. I want to do this in Caddy for example when the proxied site returns a HTTP 404, 500 statuscode for example. Is this possible in Caddy? Or can I use handle_response instead to use {http.reverse_proxy.status_code} somehow?

@francislavoie
Copy link
Member

Technically, a status code of 404 from a proxy upstream is not an error in Caddy, it's simply the response that Caddy received from the upstream. The handle_errors routes are not triggered when a proxy responds with a non-2xx status code. This is mentioned in the docs for https://caddyserver.com/docs/caddyfile/directives/handle_errors

Yes, handle_response would be the right thing to use in this case, but you may run into issues due to this outstanding bug #4298; when the upstream has a non-empty response body, handle_response fails to work correctly when trying to write a new response. Keep an eye on that issue to find out when it's fixed.

For next time, please ask your usage questions on the Caddy community forums. We prefer to keep the GitHub issue board for bugs and feature requests. Don't forget to fill out the thread template so we can help you!

@francislavoie francislavoie added the question ❔ Help is being requested label Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❔ Help is being requested
Projects
None yet
Development

No branches or pull requests

2 participants