Is server_name really needed for default_server? (Nginx)
I tried the 4 cases of code with default_server
below one by one in Nginx. The file default.conf
with the code is located at /etc/nginx/conf.d/default.conf
.
1st: With server_name _;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 500;
}
2nd: With a different server name(private ip) server_name 10.0.0.0;
(My computer's private ip is 10.156.58.216
)
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 10.0.0.0;
return 500;
}
3rd: With server_name "";
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name "";
return 500;
}
4th: Without server name
server {
listen 80 default_server;
listen [::]:80 default_server;
return 500;
}
My computer's private ip is 10.156.58.216
.
Then, the results are all the same showing 500 Internal Server Error
page.
I think for default server
, we don't need server name
. So the 4th code without server name
is fine to use.
4th: Without server name
server {
listen 80 default_server;
listen [::]:80 default_server;
return 500;
}
I ask again, Is server name
really needed for default server
?
From the Nginx documentation:
If no server_name is defined in a server block then nginx uses the empty name as the server name.
Regarding server_name _;
, the same document states:
There is nothing special about this name, it is just one of a myriad of invalid domain names which never intersect with any real name.