Organizing .conf apache configuration per domain

Solution 1:

It'll be much easier to manage all vhosts in their own separate configuration file. Here is what I would do (on Debian):

Place each vhost configuration in its own file inside /etc/apache2/sites-available/. Use a2ensite to create a symlink between the available vhost sites and the /etc/apache2/sites-enabled directory.

Then just add:

Include /etc/apache2/sites-enabled/

To httpd.conf

This way you can easily take sites offline, with a2dissite vhostname, for example: a2dissite mydomain.com

Since you have CentOS, the a2ensite script will not be present. Here's a way to simulate the Debian scripting methods:

http://cosp.org.pk/blog/shoaibi/2009/12/11/open-source/simulating-debian-apache-configuration-management-on-centos/

Solution 2:

By default (at least in CentOS 6.2), Apache is configured to automatically include any configuration files located in the following directory:

/etc/httpd/conf.d/

Search your httpd.conf for the following line (add if it's not there):

Include conf.d/*.conf

Then just create config files for each virtual host:

/etc/httpd/conf.d/google.com.conf
/etc/httpd/conf.d/serverfault.com.conf

And if you want to disable a virtual host, just rename:

/etc/httpd/conf.d/serverfault.com.conf.backup

Simple!