Custom error page within a proxy (e.g if responded with status 404)

Hello,

Wondering if a proxy responded with an error code of 404, let’s say, if it’s possible to give it a custom error page that is itself a proxy. Here’s an example, in NGINX (which I use, and want to switch over to caddy):

 location / {
                proxy_set_header                X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header                Host $http_host;
                server_name_in_redirect         on;
                proxy_intercept_errors          on;
                proxy_pass                      http://127.0.0.1:8085$uri;
                error_page                      404 = @redirector;
        }


        location @redirector {
                server_name_in_redirect         on;
                proxy_set_header                X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header                Host $http_host;
                proxy_set_header X-Forwarded-Referrer $http_referer;
                proxy_pass_header Referrer;
                proxy_pass_header Referer;
                proxy_pass                      http://127.0.0.1:8081$uri;
        }

Please tell me this is possible in Caddy? I really wanted to switch.

Thanks,

Ella

This is possible in Caddy 2, yes. It’s in beta right now. Would you be willing to give it a try? Your feedback can help improve it!

Yeah, of course. I’m already building from source so…

Would you mind telling me how it could be done?

Awesome! Thanks.

Just follow the instructions on the v2 branch: https://github.com/caddyserver/caddy/tree/v2

Documentation is here: Home · caddyserver/caddy Wiki · GitHub

You can define a separate routes for handling errors returned from the main handler chain: Home · caddyserver/caddy Wiki · GitHub

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.