# Multiple add\_header directives in different contexts

**URL:** <https://www.ruby-forum.com/t/multiple-add-header-directives-in-different-contexts/212889>\
**Category:** NGINX\
**Created:** [October 17, 2011, 7:52am UTC](https://www.ruby-forum.com/t/multiple-add-header-directives-in-different-contexts/212889 "2011-10-17T07:52:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [October 17, 2011, 7:52am UTC](https://www.ruby-forum.com/t/multiple-add-header-directives-in-different-contexts/212889/1 "2011-10-17T07:52:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bfsog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bfsog](https://www.ruby-forum.com/u/bfsog)\
**Post date:** [October 17, 2011, 9:01am UTC](https://www.ruby-forum.com/t/multiple-add-header-directives-in-different-contexts/212889/2 "2011-10-17T09:01:01Z")

</div>

On Mon, Oct 17, 2011 at 1:51 PM, Andrew B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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 🙂

Regards,  
-agentzh
