Score:0

Why does nginx respond to IP address without a default_server directive?

us flag

I have an nginx webserver with two sites that listen to port 80 for two domains: dom.net and dom.se

In sites-enabled I have files for each of these, dom.net.site and dom.se.site, which are identical but for the server_name directive. It is either server_name dom.net *.dom.net; or server_name dom.se *.dom.se;. The rest is virtually the same but for a location to help me debug and it looks like this (for the .net site):

  location /check {
    return 200 'dom.net';
    add_header Content-Type text/plain;
  }

What I don't understand is why when I go to http://my-server-ip/check I get the same response as if I go to http://server.dom.net/check. I have no default_server directive in any of the site files and still nginx responds to the ip-address.

And why did it pick http://server.dom.net and not http://server.dom.se?

Very confused.

in flag
usually alphabetical order.
Drifter104 avatar
ca flag
Type nginx -T and you'll see the complete nginx.conf the one that is higher up in the config file will be the site that handles all other requests
Richard Smith avatar
jp flag
See [how Nginx processes a request](http://nginx.org/en/docs/http/request_processing.html).
us flag
This is a design choice nginx developers have made at some point: There is no explicit "null" `server` block for default. Some `server` block is always used as the default one. Which one it is, can be seen from Richard's link above. Also, nginx listens on port 80 / 443 or anything else that is configured. It must answer something to every request. So, you cannot prevent answering to an IP address without specifying a `server` block for that.
Score:0
vi flag

There is a default config for nginx in the following path : /etc/nginx/nginx.conf if you read it there is a block with "http{}" syntax and in that block there is a line that says

include /etc/nginx/sites-enabled/*

So what nginx will do is loading files in that directory in order ( alphabetical order ) as "Gerald Schneider" mentioned in comment

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.