How do i set which apache virtual host will my ip go to

December 20, 2016 8.5k views
Apache Ubuntu 16.04

I follow this step How To Set Up Apache Virtual Hosts on Ubuntu 16.04

when i type it’s show
when i type it’s show
when i type my server ip it’s show

my problem is i want to set my server ip to show or not show anything. where can i set it.


1 Answer

Default virtual host will be the first loaded one. If you have multiple virtual hosts in same file, first from file will be default. If you have them in multiple files, VHost in first file will be default.

File are sorted alphabetical, with files starting with digit having highest priority:


So let’s say you have enabled following hosts (you can see enabled hosts using ls -l /etc/apache2/sites-enabled):

Sample Output

You want to be default but it isn’t.
Disable it using a2dissite:

  • sudo a2dissite

Now rename it so it comes before

  • sudo mv /etc/apache2/sites-available/ /etc/apache2/sites-available/

Enable it once again and restart Apache:

  • sudo a2ensite
  • sudo systemctl restart apache2

Try to visit site via IP, it should be working correctly this time.

  • Is there a way to access an alternate virtual domain by way of just a path? I just changed some DNS to move to a different droplet - and I want to migrate the database between admin panels / but now I don’t have a clean way to get to the old admin panel.

Have another answer? Share your knowledge.

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