remove default nginx welcome page when access directly from ip address remove default nginx welcome page when access directly from ip address nginx nginx

remove default nginx welcome page when access directly from ip address


I think when you first set up nginx it comes with a "default" virtual host. Did you tried removing that? Did you tried deleting the symlink? A third option would be to add a "deny all;" on the location / of the default virtual host.

I am not exactly sure if that will work and I cannot test it right now. If the above do not work, try this out: http://nginx.org/en/docs/http/request_processing.html#how_to_prevent_undefined_server_names

http://your-server-ip/ is a request with undefined server name. You should be able to block it with:

server {    listen      80;    server_name "";    return      444;}


You need to remove the file default, located in /etc/nginx/sites-enabled:

rm /etc/nginx/sites-enabled/default

Then restart nginx:

service nginx reload


If you want to remove the default nginx server block you can use the command:

sudo unlink /etc/nginx/sites-enabled/default

This removes the symlink from the folder: /etc/nginx/sites-enabled/.

There will still be file /etc/nginx/sites-available/default but it will not be active anymore.

If you have another server block that handles your domain e.g. example.com with some website there, than if someone goes to ip address of your server, than your website for example.com will be served.

If you have multiple domains, you need multiple server blocks. To ensure that one of those blocks serves as default one you can edit /etc/nginx/sites-available/example.com to have default_server option in the listen directive, e.g.:

server {    listen 80 default_server;    listen [::]:80 default_server;    root /var/www/html;    index index.html index.htm index.nginx-debian.html;    server_name _;    location / {            try_files $uri $uri/ =404;    }}