Input Headers. - headers_more_module.

agentzh agentzh at gmail.com
Thu Aug 30 19:09:42 UTC 2012


Hello!

On Thu, Aug 30, 2012 at 10:12 AM, David | StyleFlare
<david at styleflare.com> wrote:
> I am trying to figure out what I dont see request headers added to the
> request.
>
> I am trying to add 'X-Server-ID: $id'
>
> Here is a snippet form my config.
>
> location /{
>     more_set_input_headers 'X-Server-ID: $id';
>     more_set_headers 'X-Server-ID: $id';
>
>     uwsgi_pass://upstream;
> }
>
>
> I see X-Server-ID sent in the response headers, but my upstream application
> does not seem to get the Header Variable.
>

The more_set_input_headers directive runs at the end of the nginx
"rewrite" phase and I think your $id variable just didn't have a value
(yet) at that phase.

You can try inserting a constant header like this:

    set $id "My-ID";
    more_set_input_headers "X-Server-ID: $id";

I've tested the following example with nginx 1.2.3 and ngx_headers_more 0.18:

    location = /t {
        set $id "123456";
        more_set_input_headers 'X-Server-ID: $id';
        uwsgi_pass 127.0.0.1:1234;
    }

And then in another terminal, start "nc" to listen on the local port, 1234:

    $ nc -l 1234

And then accessing the /t location defined above:

    $ curl localhost:8080/t

assuming your nginx is listening on the local port 8080.

And now on the terminal running "nc", you should get something like
this (omitted those non-printable bytes):

    H	HTTP_HOST	localhostHTTP_CONNECTIONCloseHTTP_X_SERVER_ID123456

We can see that the X-Server-ID request header name and its value,
"123456", are indeed sent by ngx_uwsgi.

Best regards,
-agentzh



More information about the nginx mailing list