Multiple add_header directives in different contexts

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? is there any way to have multiple add_header directives in
separate contexts work as i would expect? that is, every response
includes “X-Bleep: bloop” but only requests matching the first server
block should have “X-Foo: bar” as well?

i know i could add the first add_header directive to every server
block, but i have a lot of server blocks and this header may have to
change so it would be a maintenance nightmare.

thanks for your help!

amb

On Mon, Oct 17, 2011 at 1:51 PM, Andrew B. [email protected]
wrote:

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 :slight_smile:

Regards,
-agentzh