Default Virtual Host in Apache

If you have multiple domains installed in a virtual host configuration with one IP address in Apache, the IP address may not resolve to the domain you prefer. Let me explain.

For example, you have the following domains running on an Ubuntu Server with one IP address.

abc.com
cde.com
klm.com
xyz.com

All the domains are resolving as expected on the browser.

However, if you type the IP address on the browser, it only defaults to the first domain found in the /etc/apache2/sites-available directory, which is most likely abc.com.

If you want the IP address to default to another domain, such as klm.com for example, you will need to edit the /etc/apache2/httpd.conf file and add the following entries.

<VirtualHost *:80>
ServerName www.klm.com
ServerAlias klm.com
DocumentRoot /var/www/klm.com/www
</VirtualHost>

Those are the only entries you’ll need. Typing the IP address on the browser will now default to the contents of klm.com. All the other domains are still accessible via domain names on the browser.