Are headers set in the server block inherited to all location blocks

Francis Daly francis at daoine.org
Wed Feb 5 13:33:34 UTC 2014


On Wed, Feb 05, 2014 at 01:49:59AM -0500, justink101 wrote:

Hi there,

> I was under the impression that if you set headers in the
> server block, ALL location blocks below inherit those headers.

No.

Can you say where you got that impression? Perhaps documentation can be
clarified or corrected.


The request is handled in one location block.

Only the configuration in, or inherited into, that location block,
matters.

Configuration in the location block overrides anything that might otherwise
have been inherited.

> location ~* \.(?:ico|js|css|gif|jpe?g|png|xml)$ {
>   expires 7d;
>   add_header Pragma public;
>   add_header Cache-Control "public, must-revalidate, proxy-revalidate";

"add_header" here means that no "add_header" directives are inherited --
only these two apply.

> When requesting a .js file, the Pragma and Cache-Control headers are set,
> but all the headers set in the base server block are not.

That is working as intended.

> What is the fix here?

If you want configuration in the location block, put all of the
configuration in the location block.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list