Apache 2.2忽略了VirtualDocumentRoot VirtualHosts?

时间:2009-04-24 14:01:38

标签: apache2 virtualhost apache httpd.conf

我有几个域名,我希望通过mod_vhost_alias启用通配符子域

我的httpd.conf中包含以下通用规则:

<VirtualHost [ip here]:80>
    ServerName domain1.com
    ServerAlias www.domain1.com
    DocumentRoot /home/user1/public_html
</VirtualHost>
<VirtualHost [ip here]:80>
    ServerName *.domain1.com
    VirtualDocumentRoot /home/user1/subdomains/%-3+
</VirtualHost> 

<VirtualHost [ip here]:80>
    ServerName domain2.com
    ServerAlias www.domain2.com
    DocumentRoot /home/user2/public_html
</VirtualHost>
<VirtualHost [ip here]:80>
    ServerName *.domain2.com
    VirtualDocumentRoot /home/user2/subdomains/%-3+
</VirtualHost>

问题是apache完全忽略了带有通配符ServerNames的虚拟主机。对test.domain1.com或test.domain2.com的任何请求都只显示/ home / user1 / public_html(根据apache的默认规则)的内容。

其他一些信息:

/home/user1/subdomains/test/home/user2/subdomains/test都存在且包含文件

我的所有域都有一个在bind config中列出的通配符子域,它们指向Vhost规则中指定的相同IP。子域的标准Vhost规则有效,但不是通配符。

httpd -S

输出的剪切版本
# httpd -S
VirtualHost configuration:
[ip here]:80      is a NameVirtualHost
         default server domain1.com (/etc/httpd/sites/user1:1)
         port 80 namevhost domain1.com (/etc/httpd/sites/user1:1)
         port 80 namevhost *.domain1.com (/etc/httpd/sites/user1:14)
         port 80 namevhost domain2.com (/etc/httpd/sites/user2:1)
         port 80 namevhost *.domain2.com (/etc/httpd/sites/user2:14)
Syntax OK
# httpd -M
Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 rewrite_module (shared)
 auth_basic_module (shared)
 authz_host_module (shared)
 include_module (shared)
 log_config_module (shared)
 logio_module (shared)
 mime_magic_module (shared)
 mime_module (shared)
 vhost_alias_module (shared)
 dir_module (shared)
 suexec_module (shared)
 php5_module (shared)
 suphp_module (shared)
 ssl_module (shared)
Syntax OK

非常感谢任何有关问题的建议。

2 个答案:

答案 0 :(得分:11)

我是一个菜鸟,这是一个非常简单的解决方案。

ServerName不允许使用通配符,但是ServerAlias会执行,因此我只是重复了服务器名称。

这是域名的最终最小化配置,任何碰巧找到这个答案的人(我讨厌在谷歌搜索并找到问题但没有答案时):

<VirtualHost [ip here]:80>
    ServerName domain1.com
    ServerAlias www.domain1.com
    DocumentRoot /home/user1/public_html
</VirtualHost>
<VirtualHost [ip here]:80>
    ServerName domain1.com #<-- The fix. Wildcards not supported in ServerName
    ServerAlias *.domain1.com
    VirtualDocumentRoot /home/user1/subdomains/%-3+
</VirtualHost>

答案 1 :(得分:0)

David,这个解决方案在成功对你的问题有用时停止mod_rewrite循环。)

重写循环塞:

RewriteCond %{ENV:REDIRECT_STATUS} 200|[45]0[0-9]
RewriteRule .* - [L]