Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;


server {
 listen 80;
 server_name *;
 root /www/prelive;

 auth_basic "Restricted";
 auth_basic_user_file /etc/htpasswd;


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

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


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.