Opened 10 years ago

Closed 10 years ago

Last modified 5 years ago

#754 closed defect (worksforme)

add_header not being inherited by named location

Reported by: Neil Craig Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.7.x
Keywords: add_header header Cc:
uname -a: Linux ip-10-13-145-14.eu-west-1.compute.internal 2.6.32-504.16.2.el6.x86_64 #1 SMP Wed Apr 22 06:48:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.7.12
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/current/nginx.conf --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=gtmdaemon --group=gtmdaemon --with-http_perl_module --with-http_realip_module --with-http_spdy_module --with-http_ssl_module --with-http_sub_module --with-http_geoip_module --with-file-aio --with-pcre-jit --with-ipv6 --add-module=/tmp/tmpNRGtDs/BUILD/nginx-1.7.12/headers-more-nginx-module --add-module=/tmp/tmpNRGtDs/BUILD/nginx-1.7.12/naxsi/naxsi_src --add-module=/tmp/tmpNRGtDs/BUILD/nginx-1.7.12/ngx_cache_purge --add-module=/tmp/tmpNRGtDs/BUILD/nginx-1.7.12/nginx-statsd --add-module=/tmp/tmpNRGtDs/BUILD/nginx-1.7.12/nginx_upstream_check_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

Description

Hi

I am developing an service based on nginx which uses it as a reverse proxy - similar to a CDN. My usage involves using the include config method from nginx to include several "listeners" (which in turn include some layer 7 routes - locations). My listeners include a named location which error pages are pointed at via:

error_page 400 =400 @default_error_pages;

location @default_error_pages {
...
}

I came across what I believe is a bug this morning wherein the add_header methods used as global header setters in nginx.conf are not issued by requests which are served by my named location - even when I used the "always" flag - e.g. add_header "Some-Header" "Some value" always;. I haven't checked it out in huge detail but it may be that add_header isn't working at all in my named location.

I can work around the issue by using more_set_headers as I have this compiled in.

Happy to check things out if it'd be any use.

Neil

Change History (3)

comment:1 by Sergey Kandaurov, 10 years ago

Resolution: worksforme
Status: newclosed

Looks like you have add_header directive(s) inside your named location.
If this is the case, you might want to re-read about add_header inheritance.
See for more details: http://nginx.org/r/add_header

comment:2 by cawoodm@…, 5 years ago

So there is no way to define some headers on the server level and others on the location level. This is a strange limitation. If I define "Cache-Control" on one location it now stops inheriting "X-Something" headers from the server level. Why is this done? Surely you should only stop inheriting if the *same* header is defined below not just all headers...

comment:3 by Maxim Dounin, 5 years ago

You may find this Igor's talk interesting:

https://youtu.be/YWRYbLKsS0I

In particular, it explains a similar case: why locations cannot be specified at the "server" level (tldr: because practice showed that such configurations are very hard to support) and how to deal with it if you really need to (tldr: use include).

Note: See TracTickets for help on using tickets.