Understanding locations (multiple locations that do different things)

E.B. emailbuilder88 at yahoo.com
Wed Apr 8 05:00:34 UTC 2015


I'm new to Nginx, coming from Apache. Now I'm struggling with
how to apply multiple configs and rules to different location (request

Easy example, a server/site has PHP support for all of its requests
but only one of its directoryies needs to have HTTP AUTH.

I had:

location ~* \.php$ {...PHP settings...}
location /admin {...HTTP AUTH settings...}

After reading about locations now I understand that ONLY ONE gets used.
Which means PHP was working fine but HTTP AUTH was only protecting
the non-PHP files in /admin! Am I correct?

I know I can nest location blocks but when I tested, it doesn't look like
the settings in the outer block are inherited by the inner block, so the
only advantage to nesting is just narrowing the request type handled by
the block.

For example, if I nest "location /admin" inside the PHP block I still have
to repeat the entire PHP setup parameters inside the /admin block. Plus
I still need another /admin block outside the PHP block to have HTTP
AUTH on the non-PHP files in /admin. This gets repetative and messy.

So what's the most smoothe way to have one or more location handlers
that need to be *addative* like having a global handler for PHP files in
addition to handlers that are specific to the directory, like HTTP AUTH
or other things?


More information about the nginx mailing list