Matching server host name in location directive

Francis Daly francis at
Tue Jul 5 12:04:31 MSD 2011

On Tue, Jul 05, 2011 at 11:19:23AM +0530, Quintin Par wrote:

Hi there,

>   I have nginx running multiple domains under a single server directive as
>   server {
>           listen       80;
>           server_name;
>           server_name;

>   Now, I need to use location directive to match a subdomain and apply basic
>   auth to it. The equivalent of

location doesn't match subdomains. server_name matches subdomains. Use
different server{}s for different things.

>   location {
>           auth_basic "Admin Login";
>          auth_basic_user_file /etc/nginx/.htpasswd;
>   }
>   How do I do this using DRY?


Or m4. Or a config file generator of your choice.

nginx doesn't care how your .conf file came about, it just cares about
what is in the .conf file when it is loaded.

Don't worry about duplication or repetition in the generated output
file. If you want to worry about repetition, do it in your input format.

Good luck,

Francis Daly        francis at

More information about the nginx mailing list