Redirect request based on request type in case of error

devkuamr nginx-forum at
Tue Jan 9 06:04:22 UTC 2018

I want to redirect GET request to another server in case of errors. I am
using the below configuration but nginx is having problem while starting
with this configuration.

worker_processes  8;
events {
   worker_connections  1024;
http {
                include       mime.types;
                include       map.txt;
                default_type  application/octet-stream;
                sendfile        on;

                        upstream 271889976{

                        upstream 271889979{

                upstream backup {

        server {
                listen       8080;
                server_name  localhost;
                proxy_intercept_errors on;
                        error_page 502 @redirect;
                        proxy_read_timeout 10s;
                location / {
                                proxy_pass http://$newhost$request_uri;
                                proxy_hide_header store;
                        location @redirect{
                               if ($request_method = GET){
                                if ($request_method = POST){
                                        return upstream_status;



        include servers/*;

I am getting "invalid return code "upstream_status"" with above
configuration file.

For POST request I want the same error returned by server. and in case of
GET I want request to be redirected on "backup upstream".

Posted at Nginx Forum:,278044,278044#msg-278044

More information about the nginx mailing list