Nginx default host when not defined

nginx

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.

Best Answer

http://nginx.org/en/docs/http/request_processing.html

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.