How to prohibit direct access to my site with ip?

I have purchased a digital ocean droplet running Apache and have linked it with a domain Currently in some 11 digit IP address after type in the browser like I can view the website and so can the public. My droplet is running on Ubuntu 18.04 LTS. How would I go about only allowing access when typed in and but just make the browser keep on trying but be unable to access directly using the IP address? Thank you.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

What I could suggest is adding a Vhost for your website as described here:

After that in your default Vhost, change the document root so that it does not match the document root of your site.

For example:

  • In your websites Vhost set the document root to /var/www/ and put your website files there

  • And in your default Vhost set the document root to: /var/www/html and put the default Apache index.html file there

That way if someone visits your domain name they would get the content from /var/www/ and if someone visits your IP they would just get the Apache default page from /var/www/html.

Hope that this helps! Regards, Bobby