How to change IP access from web browesr having vHosts?

Hi, I need some help here. I’m using CentOS 6.8 and Apache. I have two working virtual hosts already set and everything is working fine but if I enter the IP of my droplet in the web browser it access one of the two virtual hosts (I believe this is because somewhere this is set by default). The folder for the documents are set like this “/var/www/html/” and “/var/www/html/”. I want, if possible, to change or redirect the access through the IP so that it does nothing, I mean, I can access to phpmyadmin (only allowed from my home computer) using the droplet’s IP but I want that if I enter just the IP, don’t show anything.

Thanks a lot in advance


Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Accepted Answer

Apache will always display the first virtualhost in it’s configuration if a VirtualHost does not match with what is requested (as with the IP address). You can specify a third VirtualHost block in your configuration that does not have a ServerName or ServerAlias directive to direct requests for the IP address to a different folder on your droplet:

<VirtualHost *>
DocumentRoot /var/www/default

Place this in a file in /etc/apache2/sites-enabled that would come alphabetically first in a list of the files in that directory (sorting is 0-9 then A-Z). Then create the directory /var/www/default (or make sure you are specifying a directory that already exists) with an index.html file. If you want nothing to display you can create a blank index.html file.

Once you’ve done this, reload your apache configuration and you should be all set:

service apache2 reload

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Thanks for the quick reply. That’s what I thought and did just after writting my question :D. I did another folder and redirect there (with a simple html page).

Thanks again