Matching server host name in location directive

Edho P Arief edho at myconan.net
Tue Jul 5 10:03:24 MSD 2011


On Tue, Jul 5, 2011 at 12:49 PM, Quintin Par <quintinpar at gmail.com> wrote:
>  Can someone help me answer this question at
>   serverfault.com<http://serverfault.com/questions/286828/nginx-matching-server-host-name-in-location-directive>?
>
> -------
>   Posted again
>
>   I have nginx running multiple domains under a single server directive as
>   server {
>           listen       80;
>           server_name  www.domain.com;
>           server_name  x.domain.com;
>           server_name  y.domain.com;
>   ----
>   ----
>   ----
>   }
>
>   Now, I need to use location directive to match a subdomain and apply basic
>   auth to it. The equivalent of
>
>   location x.domain.com {
>           auth_basic "Admin Login";
>          auth_basic_user_file /etc/nginx/.htpasswd;
>   }
>
>   How do I do this using DRY?
>

server {
  server_name  www.domain.com;
  server_name  y.domain.com;
  include myapps.conf;
}

server {
  server_name  x.domain.com;
  include myapps.conf;
  auth_basic "Admin Login";
  auth_basic_user_file /etc/nginx/.htpasswd;
}




More information about the nginx mailing list