0

I am using named location for forwarding request to certain named blocks based on certain conditions. This is how my current config looks like

server {
    listen       8080;
    server_name  localhost;


    error_page 420 = @handler;

    location / {
        if ($http_x_client = 'handler'){
             return 420;
        }
        error_page 500 = @fallback;
        proxy_intercept_errors on;
        proxy_pass  http://www.example.com;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
   }

   location @fallback{
        proxy_pass  http://www.example2.com;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
   }

   location @handler{
        proxy_pass  http://www.example3.com;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
   }

}

Now when i am hitting the page including the header X_Client=handler it's returning 420 status instead of going to @handler block. I have narrowed it down to a issue with the line

error_page 500 = @fallback; 

Can someone what's wrong with this configuration or is this is a expected nginx behaviour?

1 Answer 1

1

A quote from the documentation:

error_page directives are inherited from the previous level only if there are no error_page directives defined on the current level.

It's a basic rule for most of the directives in nginx.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.