nginx usptream 302 redirect

Anatoli Marinov a.marinov at ucdn.com
Fri Oct 4 14:33:57 UTC 2013


Hello,
Is there an easy way to configure nginx upstream to follow 302 instead of
send them to the browser?

I tried with this config:

http {
    proxy_intercept_errors on;

    proxy_cache_path /home/toli/nginx/run/cache keys_zone=zone_c1:256m
inactive=5d max_size=30g;

    upstream up_servers {
        server 127.0.1.1:8081;
    }

    server {
        listen 127.0.0.1:8080;

        location / {
            proxy_cache zone_c1;
            proxy_pass http://127.0.1.1:8081;
            proxy_temp_path tmp ;

            error_page 301 302 307 @redir;
        }

        location @redir {
            proxy_cache zone_c1;
            proxy_pass $upstream_http_location;
            proxy_temp_path tmp ;
        }
    }
}

Unfortunately it do not work. I receive "500: Internal Server Error."
and in the logs I have [invalid URL prefix in ""]

>From dev mail list Maxim advised me to backup $upstream_http_location in
other variable and I did it but the result was the same - 500 internal
server error. The config after the fix is:


http {
    proxy_intercept_errors on;

    proxy_cache_path /home/toli/nginx/run/cache keys_zone=zone_c1:256m
inactive=5d max_size=30g;

    upstream up_servers {
        server 127.0.1.1:8081;
    }

    server {
        listen 127.0.0.1:8080;

        location / {
            proxy_cache zone_c1;
            proxy_pass http://127.0.1.1:8081;
            proxy_temp_path tmp ;
            set $foo $upstream_http_location;
            error_page 301 302 307 @redir;
        }

        location @redir {
            proxy_cache zone_c1;
            proxy_pass $foo;
            proxy_temp_path tmp ;
        }
    }
}

Do you have any idea how this could be achieved.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20131004/e1331af9/attachment.html>


More information about the nginx mailing list