# Using add\_header at server level context

**URL:** <https://www.ruby-forum.com/t/using-add-header-at-server-level-context/236751>\
**Category:** NGINX\
**Created:** [September 30, 2013, 3:44pm UTC](https://www.ruby-forum.com/t/using-add-header-at-server-level-context/236751 "2013-09-30T15:44:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [September 30, 2013, 3:44pm UTC](https://www.ruby-forum.com/t/using-add-header-at-server-level-context/236751/1 "2013-09-30T15:44:01Z")

</div>

From the add\_header docs I understand that it works at location, http  
and  
server context. But when I use add\_header at the server level I don’t  
see  
the headers being added to the response.

For example my server config starts with:

server {  
listen 9088;  
server\_name localhost;  
tcp\_nodelay on;

```
etag on;
access_log on;

add_header X-AppServer $upstream_addr;
add_header X-AppServer-Status $upstream_status;
add_header X-Cache $upstream_cache_status;

```

Am I missing something or is this just not working at the server level  
for  
some reason?

---

<div class="post-metadata">

**Author:** ![Thijs\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/53a042/32.png) [@Thijs\_K](https://www.ruby-forum.com/u/Thijs_K)\
**Post date:** [September 30, 2013, 4:30pm UTC](https://www.ruby-forum.com/t/using-add-header-at-server-level-context/236751/2 "2013-09-30T16:30:46Z")

</div>

On Mon, Sep 30, 2013 at 03:42:50PM +0200, Thijs K. wrote:

Hi there,

> From the add\_header docs I understand that it works at location, http and  
> server context. But when I use add\_header at the server level I don’t see  
> the headers being added to the response.

> Am I missing something or is this just not working at the server level for  
> some reason?

You’re missing something.

You’re either missing that if the second argument to add\_header expands  
to empty, then the header is not added; or that configuration directive  
inheritance is by replacement, not addition.

==  
server {  
listen 8080;  
add\_header X-Server server-level;  
add\_header X-Surprise $http\_surprise;

```
location /one {
  return 200 "location one";
}
location /two {
  return 200 "location two";
  add_header X-Location two;
}

```

# }

Compare the outputs you actually get from

curl -i [http://127.0.0.1:8080/one](http://127.0.0.1:8080/one)

curl -i [http://127.0.0.1:8080/two](http://127.0.0.1:8080/two)

curl -i -H Surprise:value [http://127.0.0.1:8080/one](http://127.0.0.1:8080/one)

with what you expect to get.

## f

Francis D. removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Thijs\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/53a042/32.png) [@Thijs\_K](https://www.ruby-forum.com/u/Thijs_K)\
**Post date:** [October 7, 2013, 4:04pm UTC](https://www.ruby-forum.com/t/using-add-header-at-server-level-context/236751/3 "2013-10-07T16:04:00Z")

</div>

Thanks. So using add\_header in the location scope omits any earlier  
add\_header statements used in the parent scope. I am surprised that it  
works like that, but it’s definitely good to know.
