Redirect to Error Page

1. My Caddy version (caddy version):

2.0rc3

2. How I run Caddy:

a. System environment:

Ubuntu Systemd

d. My complete Caddyfile or JSON config:

               {
                  "handler": "reverse_proxy",
                  "headers": {
                    "request": {
                      "set": {
                        "Host": [
                          "mylodocs.s3-website-us-west-2.amazonaws.com"
                        ]
                      }
                    },
                    "response": {
                        "require": {
		             "status_code": [2, 3]
                        }
                    }
                  },
                  "upstreams": [
                    {
                      "dial": "mylodocs.s3-website-us-west-2.amazonaws.com:80"
                    }
                  ]
                }
              ],
              "match": [
                {
                  "host": [
                    "*.mylodocs.com"
                  ]
                }
              ]
            }

3. The problem I’m having:

I want to redirect to an error page when i receive a 404 from an upstream server. My upstream returns a 404 and then shows an error page. But I don’t want to see that error page. I tried requiring a response of 2xx or 3xx but that didn’t seem to work as expected. Whats the best way to do this?

          "errors":{
              "routes": [{
                  "match":[{
                      "host": [
                        "*.mylodocs.com"
                    ]
                  }],
                  "handle":[{
                    "body": "Hi Error!",
                    "handler": "static_response"
                  }]
              }]
          }

Also tried this and it doesn’t seem to work

I suspect that because the “error” is coming from upstream, not generated by Caddy, Caddy isn’t handling it as an error but as a valid response to return to the user.

Off the top of my head, I don’t actually know how to “mask” a response from upstream. Outside of a custom module designed to wrap a terminal handler, which could discard its response and replace it based on some logic, I don’t think Caddy has a framework for intercepting and re-handling valid responses from other terminating handlers.

1 Like

More “error” handling (for lack of a better term) controls will be coming after the 2.0 release too. We still need to plan and design them.

Yeah, the “error” is coming from the upstream server. Ok thanks for letting me know. I’ll keep a look out in the future.

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