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

How does nginx determine the server to use when there is no default_server defined and it doesn't match server_name?

It was magically matching a server_name of localhost in the default sites-enabled file.

share|improve this question
up vote 1 down vote accepted

In this configuration nginx tests only the request’s header field “Host” to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port. In the configuration above, the default server is the first one — which is nginx’s standard default behaviour.

share|improve this answer
Is the first once alphabetical? If I have a,b,c,d should it use a? – Chris Muench Sep 27 '12 at 18:16

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.