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

Руслан Закиров ruz at sports.ru
Mon Nov 14 15:44:10 UTC 2016


On Mon, Nov 14, 2016 at 3:45 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:

> 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;
>

This helps, suspected something like this, but until the last moment
couldn't believe upstream
module re-initializes variables before request to upstream. Wonder if it
can be delayed until after
request phase.

--
> Maxim Dounin
> http://nginx.org/
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx




-- 
Руслан Закиров
Руководитель отдела разработки веб-сервисов
+7(916) 597-92-69, ruz @  <http://www.sports.ru/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20161114/bfe11ebb/attachment.html>


More information about the nginx mailing list