I have a VPS server with CentOS with multiple domains (some I own, some I don't). I host my sites and my friends sites on it.
I have this structure:
/home/myfriendsusername/public_html/
/home/myotherfriendsusername/public_html/
/var/www/mydomain.com/public_html/
So all my stuff is in my /var/www and my friends have their own username in the home folder. Every VirtualHost is in the httpd.conf and it's getting kinda big (I have over 50+ domains including sometimes sub-domains.
Will it be better to create a file in the sites-enabled for each domain I host like:
/etc/apache2/sites-enabled/myfriendsdomain.com
/etc/apache2/sites-enabled/mydomain.com
Is that a good practice? or what I did (using httpd.conf) is correct?
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/
. Usea2ensite
to create a symlink between the available vhost sites and the/etc/apache2/sites-enabled
directory.Then just add:
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:
Search your httpd.conf for the following line (add if it's not there):
Then just create config files for each virtual host:
And if you want to disable a virtual host, just rename:
Simple!
Here's an excellent link on how to: http://wiki.centos.org/TipsAndTricks/ApacheVhostDir
basically you create each config file domain in:
example:
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:
Enable a virtual host by removing the _ from the virtual host file name:
restart: