multiple add_header directives in different contexts

agentzh agentzh at gmail.com
Mon Oct 17 07:00:32 UTC 2011


On Mon, Oct 17, 2011 at 1:51 PM, Andrew Benton <andrewmbenton at gmail.com> wrote:
> so i have a configuration like this:
>
> ...
> http {
>    ...
>    add_header X-Bleep bloop;
>    server {
>        ...
>        add_header X-Foo bar;
>    }
>    server {
>        ...
>    }
> }
>
> and only "X-Bleep: bloop" is showing up in responses. is this expected
> behavior?

Yes, this is the expected behavior of the standard ngx_headers module.

Try the 3rd-party module ngx_headers_more instead:

    http://wiki.nginx.org/HttpHeadersMoreModule

It supports incremental inheritance, here's a working example from its
test suite:

    more_set_headers -s 404 -t 'text/html' 'X-status: yeah';
    location /bad {
        default_type 'text/html';
        more_set_headers -s 404 -t 'text/html' 'X-status2: nope';
        return 404;
    }

Then, request "GET /bad" will give the following response headers:

X-status: yeah
X-status2: nope

which is what you want :)

Regards,
-agentzh



More information about the nginx mailing list