Forum: NGINX Using add_header at server level context

827d1f54ddb67b01ceae7192c367978d?d=identicon&s=25 Thijs Koerselman (Guest)
on 2013-09-30 15:44
(Received via mailing list)
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?
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2013-09-30 16:30
(Received via mailing list)
On Mon, Sep 30, 2013 at 03:42:50PM +0200, Thijs Koerselman 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

  curl -i http://127.0.0.1:8080/two

  curl -i -H Surprise:value http://127.0.0.1:8080/one

with what you expect to get.

  f
--
Francis Daly        francis@daoine.org
827d1f54ddb67b01ceae7192c367978d?d=identicon&s=25 Thijs Koerselman (Guest)
on 2013-10-07 16:04
(Received via mailing list)
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.