# Add\_headers on text/html only?

**URL:** <https://www.ruby-forum.com/t/add-headers-on-text-html-only/221520>\
**Category:** NGINX\
**Created:** [July 18, 2012, 6:24am UTC](https://www.ruby-forum.com/t/add-headers-on-text-html-only/221520 "2012-07-18T06:24:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [July 18, 2012, 6:24am UTC](https://www.ruby-forum.com/t/add-headers-on-text-html-only/221520/1 "2012-07-18T06:24:59Z")

</div>

I’m trying to add three headers for security to all text/html content:

add\_header X-Content-Type-Options ‘nosniff’;  
add\_header X-Frame-Options ‘DENY’;  
add\_header X-XSS-Protection ‘1; mode=block’;

I’d like to add these to a number of different sites & virtual hosts in  
nginx.

Q: Is there an easy way to add this to multiple different hosts  
without updating every server{} block?

Can I put this into an http{} section in some way (but still limit it  
to text/html)?

## Best, Nick

Nick Semenkovich

---

<div class="post-metadata">

**Author:** ![Nick\_Semenkovich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b19c9b/32.png) [@Nick\_Semenkovich](https://www.ruby-forum.com/u/Nick_Semenkovich)\
**Post date:** [July 19, 2012, 5:55pm UTC](https://www.ruby-forum.com/t/add-headers-on-text-html-only/221520/2 "2012-07-19T17:55:22Z")

</div>

On 18.07.2012, at 8:24, Nick Semenkovich wrote:

> Can I put this into an http{} section in some way (but still limit it  
> to text/html)?

add\_header will not add header with empty value, so

```
add_header X-test $test;
map $sent_http_content_type $test {
    text/html 1;
}

```

should work.
