Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've got two nginx configs, one is a global catchall config without a server name set that should handle any request. And i got a second configuration that has a server name set that handles only the requests on a specific subdomain.

Examples (not real config but there isn't much more there at all):

server {
 listen 80;
 root /www/live;

 location
 ....
}

server {
 listen 80;
 server_name *.prelive.host.tld;
 root /www/prelive;

 auth_basic "Restricted";
 auth_basic_user_file /etc/htpasswd;

 location
 ....
}

But when I include the second one into the configuration the whole page goes password protected, not only prelive pages.

Any ideas what could cause the first config to inherit the basic auth?

share|improve this question
    
Probably a typo, bad paste, etc. –  Michael Hampton Nov 22 '13 at 19:54

1 Answer 1

It seems like nginx will "randomly" select one of the configurations as the default configuration in the mentioned setup. Our solution was to set

listen 80 default_server;

instead of

listen 80;

on the default config so nginx would always choose that configuration for anything except matched server names.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.