nginx x-accel-redirect request method named location

Руслан Закиров ruz at sports.ru
Thu Dec 15 11:21:21 UTC 2016


On Sat, Dec 10, 2016 at 9:08 PM, hemendra26 <nginx-forum at forum.nginx.org>
wrote:

> I was using nginx  x-accel-redirect as an authentication frontend for an
> external db resource.
>
> In my python code I would do the following:
>
> /getresource/
>
> def view(self, req, resp):
>      name = get_dbname(req.user.id)
>      resp.set_header('X-Accel-Redirect', '/resource/%s/' %name )
>
> This would forward the HTTP method as well until nginx 1.10
> Since nginx 1.10 all x-accel-redirects are forwarded as GET methods.
>
> From this thread:
> https://forum.nginx.org/read.php?2,271372,271380#msg-271380
>
> I understand that the correct way to forward the HTTP method is to use
> named
> location.
> I am unable to find documentation on how this should be done.
> I tried the following:
>
> def view(self, req, resp):
>         name = get_dbname(req.user.id)
>         resp.set_header('X-Accel-Redirect', '@resource'  )
>
> but this redirects to @resource /
> I would like to redirect to @resource /name
>

Hi,

Here what you do. As you can not use X-Accel-Redirect to set different
location, you should set other header with location and in nginx config do
something like this:

location @resources {
    set $stored_real_location $upstream_http_x_real_location;
    proxy_pass http://resources-backend$stored_real_location;
}

In example above Python code should set the following headers:

X-Accel-Redirect: @resources
X-Real-Location: /some/other/path...

Does it help?


>
> Posted at Nginx Forum: https://forum.nginx.org/read.
> php?2,271448,271448#msg-271448
>
> _______________________________________________
> 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/20161215/637499f2/attachment-0001.html>


More information about the nginx mailing list