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):
example.com to be default but it isn't.
Disable it using
- sudo a2dissite example.com
Now rename it so it comes before
- sudo mv /etc/apache2/sites-available/example.com.conf /etc/apache2/sites-available/000-example.com.conf
Enable it once again and restart Apache:
- sudo a2ensite 000-example.com
- sudo systemctl restart apache2
Try to visit site via IP, it should be working correctly this time.