x-accel-redirect to @location and empty $upstream_http_some_header

Maxim Dounin mdounin at mdounin.ru
Mon Nov 14 12:45:19 UTC 2016


Hello!

On Mon, Nov 14, 2016 at 02:13:18PM +0300, Руслан Закиров wrote:

> One URL redirects to @streams location:
> 
> HTTP/1.0 200 OK
> expires: 0
> cache-control: no-cache, no-store, must-revalidate
> x-accel-redirect: @streams
> Content-Type: text/html; charset=utf-8
> Status: 200
> x-real-location: /stream/?user_id=153847603&lang=RU
> pragma: no-cache
> 
> @streams
> 
> Location looks like this:
> 
> location @streams {
>     proxy_set_header X-Real-IP $header_ip;
>     ... more proxy sets...
>     proxy_set_header X-Y
> ttt$upstream_http_x_real_location$upstream_http_status;
>     proxy_set_header X-Z ttt$http_x_real_location;
>     proxy_pass http://streams-backend$upstream_http_x_real_location;
> }
> 
> However, $upstream_http_x_real_location variable is empty and request
> reaches backed with original URL.

That's expected.  All $upstream_* variables are re-initialized as 
long as proxy module starts working in a new location, and since 
there were no response yet when the proxy_pass value is evaluated, 
it resolves to an empty value.

If you want to use $upstream_* variables set by a response with 
X-Accel-Redirect, you have to store them somewhere else.  For 
example, it can be done using the "set" directive of the rewrite 
module, which is evaluated before the request is proxied:

   set $stored_real_location $upstream_http_x_real_location;
   proxy_pass http://foo$stored_real_location;

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list