# Multiple add\_header

**URL:** <https://www.ruby-forum.com/t/multiple-add-header/242613>\
**Category:** NGINX\
**Created:** [July 7, 2015, 12:20am UTC](https://www.ruby-forum.com/t/multiple-add-header/242613 "2015-07-07T00:20:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [July 7, 2015, 12:20am UTC](https://www.ruby-forum.com/t/multiple-add-header/242613/1 "2015-07-07T00:20:57Z")

</div>

Hello,

I’m using PHP with nginx 1.9.2 and it works great!  
But there’s something I don’t understand with the add\_header directive.

I use add\_header in server and location block, but it seems only the one  
in  
location is used.  
If I remove the add\_header in the location block, I get the header I  
added  
in the server block.

Here’s a short example:  
server {  
add\_header Strict-Transport-Security “max-age=604800;  
includeSubDomains”;

location = /blah {  
add\_header X-Test test;  
}  
}

If I access /blah, I’ll only get the X-Test header, while I’d like to  
get  
X-Test and Strict-Transport-Security.  
If I comment the add\_header in the blah location and access /blah, I’ll  
get  
the Strict-Transport-Security header.

How can I solve this problem, without having to duplicate/include  
“add\_header Strict-Transport-Security” everywhere?

Seems [nginx add\_header not working - Stack Overflow](http://stackoverflow.com/a/19135714) is the same problem.

Best Regards

Posted at Nginx Forum:

> **[Multiple add\_header](https://forum.nginx.org/read.php?2,260102,260102#msg-260102)**
>
> Hello, I'm using PHP with nginx 1.9.2 and it works great! But there's something I don't understand with the add\_header directive. I use add\_header in server and location block, but it seems only the one in location is used. If I remove the add\_header...

---

<div class="post-metadata">

**Author:** ![Alt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@Alt](https://www.ruby-forum.com/u/Alt)\
**Post date:** [July 7, 2015, 12:41am UTC](https://www.ruby-forum.com/t/multiple-add-header/242613/2 "2015-07-07T00:41:59Z")

</div>

Hi,

there is no chance to avoid the duplicates. I asked the same questions  
some  
time ago.  
For detailed answer on my question see  
[Re: Behavior of security headers](http://forum.nginx.org/read.php?2,256270,256279#msg-256279).

I think this will answer your question too.

Best Regards

Posted at Nginx Forum:

> **[Re: Multiple add\_header](https://forum.nginx.org/read.php?2,260102,260103#msg-260103)**
>
> Hello, I'm using PHP with nginx 1.9.2 and it works great! But there's something I don't understand with the add\_header directive. I use add\_header in server and location block, but it seems only the one in location is used. If I remove the add\_header...

---

<div class="post-metadata">

**Author:** ![Alt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@Alt](https://www.ruby-forum.com/u/Alt)\
**Post date:** [July 7, 2015, 12:56am UTC](https://www.ruby-forum.com/t/multiple-add-header/242613/3 "2015-07-07T00:56:00Z")

</div>

Hello okamzol and thanks a lot for your answer!

Yes, it’s exactly the same question, looks like I’ll need to use  
include.

Best Regards

Posted at Nginx Forum:

> **[Re: Multiple add\_header](https://forum.nginx.org/read.php?2,260102,260104#msg-260104)**
>
> Hello, I'm using PHP with nginx 1.9.2 and it works great! But there's something I don't understand with the add\_header directive. I use add\_header in server and location block, but it seems only the one in location is used. If I remove the add\_header...
