2

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.

enter image description here

Then, the results are all the same showing 500 Internal Server Error page.

enter image description here

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?

1
  • create a new configuration and test it, however listen 80 is afaik enough to use ipv4 and v6 – djdomi May 8 at 16:26
6

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.