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?