remove default nginx welcome page when access directly from ip address

Posted on Apr 14, 2023

Question

At my ubuntu server, I install nginx and setup virtual host using this article. https://www.digitalocean.com/community/articles/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3

The virtual host's domain name is like www.example.com. When I go to www.example.com, I can see my application's index page. However, when I go to the real ip address, I still see the nginx welcome page. What can I do to remove this welcome page or point to www.example.com if someone uses ip address to access my site?

I setup a A record to point ip xxx.xxx.xxx.xxx to www.example.com.

Answer

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