add_header directives in location overwriting add_header directives in server
Posted
by
user64204
on Server Fault
See other posts from Server Fault
or by user64204
Published on 2012-06-19T15:47:00Z
Indexed on
2012/09/23
21:39 UTC
Read the original article
Hit count: 295
Using nginx 1.2.1
I am able to add multiple headers using add_header
as follows:
server {
listen 80;
server_name localhost;
root /var/www;
add_header Name1 Value1; <=== HERE
add_header Name2 Value2; <=== HERE
location / {
echo "Nginx localhost site";
}
}
GET /
HTTP/1.1 200 OK
Name1: Value1
Name2: Value2
However I soon as I use the add_header
directive inside location
, the other add_header
directives under server
are ignored
server {
listen 80;
server_name localhost;
root /var/www;
add_header Name1 Value1; <=== HERE
add_header Name2 Value2; <=== HERE
location / {
add_header Name3 Value3; <=== HERE
add_header Name4 Value4; <=== HERE
echo "Nginx localhost site";
}
}
GET /
HTTP/1.1 200 OK
Name3: Value3
Name4: Value4
The documentation says that both server
and location
are valid context
and doesn't state that using add_header
in one prevents using it in the other.
Q1: Do you know if this is a bug or the intended behaviour and why?
Q2: Do you see other options to get this fixed than using the HttpHeadersMoreModule
module?
© Server Fault or respective owner