我有一个带有多个域的CentOS的VPS服务器(有些是我自己的,有些是我没有的)。 我托pipe我的网站和我的朋友网站上。
我有这样的结构:
/home/myfriendsusername/public_html/ /home/myotherfriendsusername/public_html/ /var/www/mydomain.com/public_html/
所以我所有的东西都在我的/ var / www和我的朋友有自己的用户名在主文件夹。 每个VirtualHost都在httpd.conf中,并且它变得相当大(我有超过50个域名,包括有时候子域名。
在为我托pipe的每个域启用的站点中创build文件会更好吗?
/etc/apache2/sites-enabled/myfriendsdomain.com /etc/apache2/sites-enabled/mydomain.com
这是一个很好的做法吗? 或者我做了什么(使用httpd.conf)是正确的?
这里有一个很好的链接如何: http : //wiki.centos.org/TipsAndTricks/ApacheVhostDir
基本上你创build每个configuration文件域:
/etc/httpd/conf.d/
例:
<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>
有时可能需要禁用虚拟主机。 由于/etc/httpd/conf/httpd.conf中的include指定* .conf,因此可以通过更改configuration文件名来隐藏虚拟主机。
通过向虚拟主机文件名添加_来禁用虚拟主机:
mv -v /etc/httpd/conf.d/example.conf{,_}
通过从虚拟主机文件名中删除_来启用虚拟主机:
mv -v /etc/httpd/conf.d/example.conf{_,}
重新开始:
service httpd graceful
在自己单独的configuration文件中pipe理所有虚拟主机会容易得多。 这是我会做的(在Debian上):
将每个虚拟主机configuration放在/etc/apache2/sites-available/里的自己的文件中。 使用a2ensite在可用的vhost站点和/etc/apache2/sites-enabled目录之间创build一个符号链接。
然后只需添加:
Include /etc/apache2/sites-enabled/
到httpd.conf
通过这种方式,您可以使用a2dissite vhostname轻松地将网站a2dissite vhostname离线状态,例如: a2dissite mydomain.com
既然你有CentOS,那么a2ensite脚本将不会出现。 以下是一个模拟Debian脚本方法的方法:
默认情况下(至less在CentOS 6.2中),Apache被configuration为自动包含位于以下目录中的任何configuration文件:
/etc/httpd/conf.d/
在你的httpd.conf中search下面的行(如果不存在,请添加):
Include conf.d/*.conf
然后,为每个虚拟主机创buildconfiguration文件:
/etc/httpd/conf.d/google.com.conf /etc/httpd/conf.d/serverfault.com.conf
如果你想禁用虚拟主机,只需重命名:
/etc/httpd/conf.d/serverfault.com.conf.backup
简单!