Tuesday, April 24, 2012

Apache only serving last virtual host?

I'm assuming that you have registered your various Domain Name with your respective ISP.
I was configuring my Apache to add 1 VirtualHost and in the end, even though I follow the standard configuration of adding Virtual Host, my original default ServerName was replaced by the VirtualHost ServerName. This was strange indeed. I realised that the issue is due to the missing IP Address for NameVirtualHost.


<VirtualHost www.mydomain.com:80>
  DocumentRoot /var/www/html
  ServerName www.mydomain.com
  ServerAlias www1.mydomain.com
  ErrorLog /var/log/httpd/mydomain/error_log
  CustomLog /var/log/httpd/mydomain/access_log common

<VirtualHost www.yourdomain.com:80>
  DocumentRoot /home/yourdomain/public_html
  ServerName www.yourdomain.com
  ServerAlias www1.yourdomain.com
  ErrorLog /var/log/httpd/yourdomain/error_log
  CustomLog /var/log/httpd/yourdomain/access_log common

Restart the httpd Services

# service httpd restart

For more reference, see Apache Name Based VirtualHost Example

1 comment:

Boris Borisenko said...

In fact you should use IP addres for "VirtualHost" directive instead of domain name. In your case it will be: