Organizing .conf apache configuration per domain

Here's an excellent link on how to: http://wiki.centos.org/TipsAndTricks/ApacheVhostDir

basically you create each config file domain in:

/etc/httpd/conf.d/

example:

<VirtualHost *:80>
  ServerName example.org
  ServerAlias *.example.org
  ServerAdmin [email protected]
  ErrorLog /var/log/httpd/example.err
  CustomLog /var/log/httpd/example.log combined
  DocumentRoot /var/www/example.org
  <Directory "/var/www/example.org">
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

There might be times when it is desirable to disable a virtual host. Since the include in /etc/httpd/conf/httpd.conf specifies *.conf, it is possible to hide a virtual host by changing the configuration file name.

Disable a virtual host by adding a _ to the virtual host file name:

mv -v /etc/httpd/conf.d/example.conf{,_}

Enable a virtual host by removing the _ from the virtual host file name:

mv -v /etc/httpd/conf.d/example.conf{_,}

restart:

service httpd graceful

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/


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!