# Headers set in http {} go missing after setting headers in location {}

**URL:** <https://www.ruby-forum.com/t/headers-set-in-http-go-missing-after-setting-headers-in-location/227283>\
**Category:** NGINX\
**Created:** [March 10, 2013, 5:02am UTC](https://www.ruby-forum.com/t/headers-set-in-http-go-missing-after-setting-headers-in-location/227283 "2013-03-10T05:02:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nano](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nano](https://www.ruby-forum.com/u/nano)\
**Post date:** [March 10, 2013, 5:02am UTC](https://www.ruby-forum.com/t/headers-set-in-http-go-missing-after-setting-headers-in-location/227283/1 "2013-03-10T05:02:49Z")

</div>

Here is my nginx configuration  
[http://pastie.org/private/4lceuccm9twmuiozdjnzkg](http://pastie.org/private/4lceuccm9twmuiozdjnzkg)

My nginx -V is:  
nginx version: nginx/1.2.7  
built by gcc 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC)  
TLS SNI support enabled

I noticed that when I had headers (add\_header) in the http{ } block,  
those  
headers were not being displayed when another add\_header was placed in a  
location{ } block.

How can I have global headers sent to the client, and send additional  
headers when the client reaches a location block?

Posted at Nginx Forum:

> **[Headers set in http {} go missing after setting headers in location {}](https://forum.nginx.org/read.php?2,237172,237172#msg-237172)**
>
> Here is my nginx configuration http://pastie.org/private/4lceuccm9twmuiozdjnzkg My nginx -V is: nginx version: nginx/1.2.7 built by gcc 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) TLS SNI support enabled I noticed that when I had headers (add\_header) in

---

<div class="post-metadata">

**Author:** ![nano](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nano](https://www.ruby-forum.com/u/nano)\
**Post date:** [March 10, 2013, 5:06am UTC](https://www.ruby-forum.com/t/headers-set-in-http-go-missing-after-setting-headers-in-location/227283/2 "2013-03-10T05:06:19Z")

</div>

Accidentally pasted the headers twice. The config should look like this;  
[http://pastie.org/private/lz9zjkmvd3drbo4ezsp3fg](http://pastie.org/private/lz9zjkmvd3drbo4ezsp3fg)

Posted at Nginx Forum:

> **[Re: Headers set in http {} go missing after setting headers in location {}](https://forum.nginx.org/read.php?2,237172,237173#msg-237173)**
>
> Here is my nginx configuration http://pastie.org/private/4lceuccm9twmuiozdjnzkg My nginx -V is: nginx version: nginx/1.2.7 built by gcc 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) TLS SNI support enabled I noticed that when I had headers (add\_header) in

---

<div class="post-metadata">

**Author:** ![nano](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nano](https://www.ruby-forum.com/u/nano)\
**Post date:** [March 10, 2013, 11:27am UTC](https://www.ruby-forum.com/t/headers-set-in-http-go-missing-after-setting-headers-in-location/227283/3 "2013-03-10T11:27:09Z")

</div>

On Sat, Mar 09, 2013 at 11:02:09PM -0500, nano wrote:

Hi there,

> How can I have global headers sent to the client, and send additional  
> headers when the client reaches a location block?

The short version is “you can’t”.

The longer version is “you can, but you have to configure it the  
nginx way”. Which means that in the final parsed nginx.conf, all the  
add\_header directives that you want to apply to a request are at the  
same inheritance level.

You can “include” a file containing global ones wherever you set local  
ones; or you can use a macro language to do that for you when creating  
nginx.conf.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![nano](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nano](https://www.ruby-forum.com/u/nano)\
**Post date:** [March 10, 2013, 6:50pm UTC](https://www.ruby-forum.com/t/headers-set-in-http-go-missing-after-setting-headers-in-location/227283/4 "2013-03-10T18:50:00Z")

</div>

Thank you very much Francis.

Posted at Nginx Forum:

> **[Re: Headers set in http {} go missing after setting headers in location {}](https://forum.nginx.org/read.php?2,237172,237192#msg-237192)**
>
> Here is my nginx configuration http://pastie.org/private/4lceuccm9twmuiozdjnzkg My nginx -V is: nginx version: nginx/1.2.7 built by gcc 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) TLS SNI support enabled I noticed that when I had headers (add\_header) in
