说我有一个文件夹〜/ apache /包含两个网站目录:www.website1.com www.website2.com
现在,我已经使用站点映射域到目录的可用和启用站点的configuration来设置一些事情。 我想这样做,我所要做的就是创build一个新的目录,并将适当的域指向我的服务器。
我会诚实地说,我对服务器configuration一无所知。 我想我需要一些东西
VirtualDocumentRoot ~/apache/%0
在configuration文件中。 httpd.conf文件? apache2.conf? 或者最好把它放在一个单独的configuration中,并将其包含在主configuration中?
您可以完全完成基于名称的虚拟主机,closures所有sites-enabled文件,并将VirtualDocumentRoot放入主服务器configuration中。
更有可能的是,你想要做的是在sites-available创build一个新的虚拟主机sites-available并将其符号链接到正常sites-enabled ,使其作为一个捕获所有。 命名是重要的; 它需要成为第一个按字母顺序排列的文件,以便作为默认处理。
所以:
/etc/apache2/sites-available/0-dynamic 。 给新的虚拟主机文件一些这样的内容:
<VirtualHost *:80> ServerName catchall VirtualDocumentRoot /path/to/domains/%0 <Directory /path/to/domains> Order Allow,Deny Allow from all </Directory> </VirtualHost>
a2ensite 0-dynamic 。 (如果默认仍在/etc/apache2/sites-enabled/000-default ,则将其重新命名,以便按字母顺序重新排列。 此configuration将从VirtualDocumentRoot提供dynamicconfiguration的站点,但当该块具有与请求匹配的ServerName或ServerAlias时,可以覆盖该configuration并由另一个<VirtualHost>提供服务。 如果您的“一揽子”虚拟主机的设置不适用于特定的域,这会很有用。
编辑:(添加一些我尝试设置的东西,可能会有所帮助,所有功劳都归原作者所有!
VirtualDocumentRoot
如果你得到一个错误说
Invalid command 'VirtualDocumentRoot', perhaps misspelled...
检查以确保vhost_alias模块已启用。 如果没有,运行
>sudo a2enmod vhost_alias
处理领先的www
添加以下规则(确保将实例replace为您的实际域)到0-默认文件来处理www.example.com和example.com。
RewriteEngine On RewriteCond %{HTTP_HOST} ^www.example.com$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
在这个例子中,www被剥离了所有的请求,所以目录应该是example.com。