By bewater4ever
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/domain1.com/public_html/” and “/var/www/html/domain2.com/public_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
Regards
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!
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
</VirtualHost>
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.