Apache 2.2的忽视VirtualDocumentRoot VirtualHosts? [英] Apache 2.2 ignoring VirtualDocumentRoot VirtualHosts?
问题描述
我有几个领域,我想有通过mod_vhost_alias为支持通配符子域
I have several domains that I would like to have wildcard subdomains enabled for through mod_vhost_alias
包括在我的httpd.conf我有以下通用规则:
Included in my httpd.conf I have the following generalized rules:
<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节点的virtualhosts。对于test.domain1.com或test.domain2.com任何请求都将只显示/家/ USER1 /的public_html(根据Apache的默认规则)的内容。
The problem is that apache is completely ignoring the virtualhosts with the wildcard ServerNames. Any request for test.domain1.com or test.domain2.com will just show the contents of /home/user1/public_html (the default rule according to apache).
/家庭/用户1 /子域/测试
和 /家庭/用户2 /子域/测试
同时存在,并有在他们的文件
/home/user1/subdomains/test
and /home/user2/subdomains/test
both exist and have files in them
我所有的域在绑定配置中列出的通配符子域,它们都指向了虚拟主机规则中指定的同一个IP。子域的工作标准虚拟主机的规则,而不是通配符。
All my domains have a wildcard subdomain listed in bind config, and they are pointing to the same IP specified in the Vhost rules. Standard Vhost rules for subdomains work, but not wildcard.
一个剪断的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
任何建议,问题是,这将是极大的AP preciated。
Any suggestions as to what the problem is would be greatly appreciated.
推荐答案
我这样的小白,这是一个真正简单的解决方案。
I'm such a noob, it was a real simple solution.
服务器名称
不允许使用通配符,但 ServerAlias
做,所以我只是再次重复的服务器名。
ServerName
does not allow wildcards, but ServerAlias
does, so I just duplicated the servername again.
下面是域的人谁碰巧发现这个答案最终最小化配置(我恨它,当你在谷歌搜索和查找问题,但没有答案):
Here is the final minimized config for domains anyone who happens to find this answer (I hate it when you search on google and find questions but no answers):
<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>
这篇关于Apache 2.2的忽视VirtualDocumentRoot VirtualHosts?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!