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

Francis Daly francis at daoine.org
Thu Feb 6 00:50:35 UTC 2014


On Wed, Feb 05, 2014 at 10:55:19AM -0500, justink101 wrote:

Hi there,

> Gosh that is horrible that I have to copy and paste shared headers in the
> server block, to all location blocks. Is this a conscious decision? This

It's nginx. It makes it straightforward to see what configuration applies
to a specific request.

Copy-paste isn't the only way to create the config file.

> makes maintainability very difficult as i have to do something like:

I confess I don't see how it makes maintainability difficult.

If it matters, could you explain?

(It may not matter, of course.)

You can use the nginx directive "include" to refer to another file, as
you do here; or you could use your macro-processing language of choice
to turn your preferred input format into the desired nginx.conf.

> server {

If you use

   include shared_headers.conf;

at server level, then you only need to repeat it in locations where you
want different headers added.

>      location ^~ /docs {
>         include shared_headers.conf;
> 
>         auth_basic "Docs";
>         auth_basic_user_file /etc/nginx/auth/docs.htpasswd;
>      }

So you wouldn't need it there, for example.

>      location ^~ /actions {
>           include shared_headers.conf;
> 
>           add_header Access-Control-Allow-Origin https://www.mydomain.com;
>      }

But you would need it there.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list