nginx usptream 302 redirect

Mingcai SHEN lists at ruby-forum.com
Thu Mar 19 01:44:13 UTC 2015


Hello,

Very sorry to reply on this thread again.

I have the same requirement, but I still can not get nginx to follow the
302 redirect as I want.

My configuration:


upstream backend {
        server 10.255.199.60:1220;
}


server {
        listen       1220;
        server_name  localhost;

        location / {
                proxy_pass http://backend;
                error_page 301 302 307 @redir;
                #set $foo $upstream_http_location;
        }

        location @redir {
                set $foo $upstream_http_location;
                proxy_pass $foo;
        }

    }

And when I use curl to test , I got:

# curl -v
http://101.36.99.131:1220/vds48/export/data/videos_vod/v16/videos/0/00092/791/2/2.m3u8
* About to connect() to 101.36.99.131 port 1220 (#0)
*   Trying 101.36.99.131... connected
* Connected to 101.36.99.131 (101.36.99.131) port 1220 (#0)
> GET /vds48/export/data/videos_vod/v16/videos/0/00092/791/2/2.m3u8 HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.6.0
zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 101.36.99.131:1220
> Accept: */*
>
< HTTP/1.1 302 Found
< Server: nginx/1.4.4
< Date: Thu, 19 Mar 2015 01:34:15 GMT
< Content-Length: 0
< Connection: keep-alive
< Cache-Control: no-cache
< Location:
http://10.255.199.43:1220/vds48/export/data/videos_vod/v16/videos/0/00092/791/2/2.m3u8
<
* Connection #0 to host 101.36.99.131 left intact
* Closing connection #0


What's the problem?
Thanks.
-
MC



Maxim Dounin wrote in post #1123508:
> Hello!
>
> On Fri, Oct 04, 2013 at 05:33:57PM +0300, Anatoli Marinov wrote:
>
> [...]
>
>> 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:
>
> [...]
>
>>             proxy_pass $foo;
>>             proxy_temp_path tmp ;
>>         }
>
> You need "set ... $upstream_http_location" to be executed after a
> request to an upstream was done, so you need in location @redir,
> not in location /.
>
> --
> Maxim Dounin
> http://nginx.org/en/donation.html

-- 
Posted via http://www.ruby-forum.com/.



More information about the nginx mailing list