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

ID : 131351

viewed : 7

Tags : ubuntunginxubuntu

Top 5 Answer for ubuntu - remove default nginx welcome page when access directly from ip address

vote vote

94

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; } 
vote vote

88

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 
vote vote

75

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;     } } 
vote vote

70

Configing to

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

I get 502 for all uri, including my application url.


I didn't find sites_enabled folder under /etc/nginx, instead, my default site locates in /usr/share/nginx/html

So I create another blank page located in

/usr/share/nginx/html/blank

create a blank index.html

# echo >> index.html 

then edit the default.conf

location / {     root   /usr/share/nginx/html/blank;     index  index.html ; } 

then the home page becomes blank, hiding nginx info.


By the way, if you remove

location / {     root   /usr/share/nginx/html/blank;     index  index.html ; } 

or set

location / {     try_files $uri $uri/ = 404; } 

you will get 404 on homepage, but showing "Nginx version", which is not good.

vote vote

56

If you removed default under /etc/nginx/sites-available and restarted nginx and the welcome page is still showing, then see if there is a default.conf under /etc/nginx/conf.d and delete it and then restart nginx.

Top 3 video Explaining ubuntu - remove default nginx welcome page when access directly from ip address

Related QUESTION?