I have a problem figuring out the correct configuration for Apache2 virtual hosts on Centos6 server. I have a clean Centos6 installation with apache2 (httpd) installed, and by default there is /var/www/html, /var/www/icons, /var/www/errors and /var/www/cgi-bin content folders defined which are configured in /etc/httpd/conf/httpd.conf.

I have 2 domains a.com and b.com configured, for which I created document folders /var/www/a.com and /var/www/b.com, and in the /etc/httpd/conf/httpd.conf I configured the NameVirtualHost

NameVirtualHost *:80

and added corresponding virtual hosts for a.com and b.com like

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName  a.com
    ServerAlias www.a.com
    DocumentRoot /var/www/a.com
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    <Directory "/var/www/a.com">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all

Both domain a.com and b.com are working fine and I can access them with or without www subdomain, but I am confused what should I do with the default httpd configuration and default content folders? I dont seems to be able to access the default site in /var/www/html even when calling the server with plain IP address (request is directed to a.com virtual host). I also tried to configure the server hostname as c.com and set the

ServerName c.com:80

But even still the request to c.com is getting redirected to a.com virtual host.

I dont need the default content folders created by apache, so should I just remove the /var/www/html, /var/www/icons, /var/www/errors and /var/www/cgi-bin folders and corresponding definitions on /etc/httpd/conf/httpd.conf that is

DocumentRoot "/var/www/html"
<Directory "/var/www/html" ... />
Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons" ... />
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin" ... />
Alias /error/ "/var/www/error/"
<Directory "/var/www/error" ... />

Or how should the default host be configured and accessed when virtual hosts are configured on same server?

1 Answer 1


When you use name based virtual hosting the first <VirtualHost> becomes the default host, which will also respond to all requests that don't match to domain names declared in the ServerName or ServerAlias directives of the other virtual host.

From the manual:

Main host goes away
If you are adding virtual hosts to an existing web server, you must also create a <VirtualHost> block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .