2

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?

3 Answers 3

1
+50

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
0
2

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/

5
  • why creating the conf to the sites-available and symlink to the sites-enabled? would it be easier to just create it in the sites-enabled?
    – rcs20
    Feb 15, 2012 at 22:13
  • 2
    By creating your configurations in sites-available and then symlinking them in sites-enabled, it allows you to disable sites without having to delete the configurations. There are other ways to achieve this, but this is the convention to do it this way. Feb 15, 2012 at 22:22
  • This OP is using CentOS, not Debian or Ubuntu.
    – EEAA
    Feb 16, 2012 at 0:04
  • @ErikA oh that make sense now thanks but can i keep the same logic separating the sites? and what can i do to enable / disable?
    – rcs20
    Feb 16, 2012 at 13:11
  • @rcs20 answer updated Feb 16, 2012 at 17:26
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!

1
  • On RHEL/CentOS at least, this is the RedHat-endorsed approach. In fact, doing things this way, it's exceedingly rare you'll ever have to edit httpd.conf, which is the whole point: you can do version upgrades and modify the server's mode of operation extensively by doing simple, naïve file manipulation à la that done by RPMs. The sites-available/sites-enabled approach is just another way to achieve the same goal.
    – BMDan
    Feb 26, 2012 at 15:33

You must log in to answer this question.

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