How to change IP access from web browesr having vHosts?

Posted November 16, 2016 1.9k views

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


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.

Submit an Answer
2 answers

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

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