auth_request_set into variable and lua
djczaski
nginx-forum at nginx.us
Wed Dec 5 14:27:21 UTC 2012
agentzh Wrote:
-------------------------------------------------------
> Hello!
>
> On Tue, Dec 4, 2012 at 2:18 PM, djczaski wrote:
> > Trying to get a header from an auth_request into a variable and use
> it from
> > Lua with no luck. This was the simple example I tried.
> >
>
> You're making several mistakes. See the discussion below:
>
> > location = /auth {
> > add_header X-Boo "Hello World";
>
> Mistake #1: The add_header directive from the standard ngx_headers
> module has no effect on subrequests while your location /auth here is
> accessed by a subrequest issued via the auth_request directive.
>
> > return 204;
> > }
> >
> > location /test {
> > auth_request /auth;
> > auth_request_set $test $upstream_http_x_boo;
>
> Mistake #2: The $upstream_http_XXX variables are only meaningful when
> the *current* location is configured by one of those Nginx upstream
> modules like ngx_proxy, ngx_fastcgi, ngx_uwsgi, and etc. Here your
> current location, location /test, is not configured by any Nginx
> upstream modules (neither ngx_auth_request nor ngx_lua are upstream
> modules).
>
> Mistake #3: The $upstream_http_XXX variables are only in effect for
> the current request. It won't inherit values from any other requests
> including subrequests.
>
> > add_header X-BooHoo $test;
> >
> > content_by_lua '
> > ngx.say("(" .. ngx.var.test .. ")")
> > ';
> > }
> >
>
> BTW, I'm not sure what business requirements you're trying to achieve
> here but I think you can just use access_by_lua with
> ngx.location.capture here in place of auth_request and you can inspect
> the subrequest's response headers easily in Lua.
I confirmed mistake #1 was my problem. Thank you for the help. I
benchmarked both approaches:
1.0 Nginx 1.3.8 no auth
1.4 Nginx 1.3.8 auth_request_set
1.5 Nginx 1.3.8 access_by_lua
Interestingly, Nginx 1.3.9 seemed to be about 3% slower than 1.3.8.
Surprisingly, Nginx 1.3.8 was about 8% slower than Lighttpd, which was
shocking. Serving static files, Nginx was much faster than Lighttpd.
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,233582,233601#msg-233601
More information about the nginx
mailing list