Input Headers. - headers_more_module.

agentzh agentzh at
Thu Aug 30 21:30:35 UTC 2012


On Thu, Aug 30, 2012 at 1:12 PM, David | StyleFlare
<david at> wrote:
> Thank You
> So this worked.

Cool :)

> The question is then if I am setting a value in /auth
> When does it get actually set?
> postgres_set $pg_server 0 0 required;
> Then in my location block;
> I do
> more_set_input_headers 'X-Server-ID: $pg_server';
> When is $pg_server actually set?

Are you using the ngx_http_auth_request module? The auth_request
directive runs at the access phase. The order of running phases in
nginx for any nginx locations always looks like this:

    rewrite phase  (set, rewrite, more_set_input_headers, rewrite_by_lua, etc)
    access phase  (auth_request, allow, deny, access_by_lua, etc)
    content phase  (proxy_pass, postgres_pass, uwsgi_pass, content_by_lua, etc)
    log phase (log_by_lua, etc)

A solution is to use the ngx_lua module's access_by_lua module to
replace both auth_request and more_set_input_headers, as in

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

        uwsgi_pass ...;

    location = /auth {
        postgres_query "...";
        postgres_pass ...;
        postgres_set $pg_server ...;

You can check out the ngx_lua's documentation for more details:

Best regards,

More information about the nginx mailing list