I have purchased a digital ocean droplet running Apache and have linked it with a domain example.com. Currently in some 11 digit IP address after type in the browser like 137.152.33.173 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 example.com and www.example.com but just make the browser keep on trying but be unable to access directly using the IP address? Thank you.

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.

×
1 answer

Hi there,

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

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04

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/yourdomain.com 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/yourdomain.com and if someone visits your IP they would just get the Apache default page from /var/www/html.

Hope that this helps!
Regards,
Bobby

by Brennen Bearnes
The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 16.04 server.
  • thx but not this. Like try visiting this IP 137.152.33.173 in browser, not mine, and it does not load. I want something like this @bobbyiliev

    • Hi there @johnaraon,

      Yes, this can also be achieved by adding a default Vhost. You can then add a deny from all directive directly in that Vhost so that if someone visits the IP they would get a forbidden message.

      Let me know how it goes.
      Regards,
      Bobby

Submit an Answer