Input Headers. - headers_more_module.

agentzh agentzh at gmail.com
Fri Aug 31 18:15:12 UTC 2012


Hello!

On Fri, Aug 31, 2012 at 9:12 AM, David | StyleFlare
<david at styleflare.com> wrote:
> Strangely
>
> I still dont see the header variable set.
>
> I installed nginx-lua and I added the snippet you sent me to the nginx
> config.
>

Sorry, ngx.location.capture disables nginx variable sharing between
subrequests and their parent by default (for safety reasons). You need
to explicitly allow that for your variable:

    ngx.location.capture("/auth", { share_all_vars = true })

See the official documentation of ngx_lua for more details:

    http://wiki.nginx.org/HttpLuaModule#ngx.location.capture

But it's highly recommended to use the response body and/or headers
(instead of nginx variables) to return data from the subrequest back
to its parent, for example:

    location / {
        access_by_lua '
            local res = ngx.location.capture("/auth")
            if res.status == 200 and res.body then
                ngx.req.set_header("X-Server-ID", res.body)
            end
        ';

        uwsgi_pass ...;
    }

    location = /auth {
        internal;
        postgres_query "select server_id from ...";
        postgres_pass backend;
        postgres_output  value 0 0;
    }

That is, we use the postgres_output directive instead of postgres_set
in location /auth here so that the server ID data will be returned as
the subrequest's response body.

Best regards,
-agentzh



More information about the nginx mailing list