通配符子域和静态子域的虚拟主机
我有一个奇怪的情况,我希望 URL app1.example.com
、example.com
和 *.example.com
全部使用不同的虚拟主机。 这就是我所拥有的(不包括 example.com
因为它只会让事情变得更混乱)。
<VirtualHost *>
ServerName app1.example.com
ServerAlias app1.example.com
DocumentRoot = /var/www/app1
# Other configuration for this app here
</VirtualHost>
<VirtualHost *>
ServerName wildcard.example.com
ServerAlias *.example.com
DocumentRoot = /var/www/wildcard
# other configuration for this app here
</VirtualHost>
问题是它们是冲突的。 最先列出的一方获胜。 如何同时托管通配符虚拟主机和特定虚拟主机?
注意:我不只是更改配置中的 DocumentRoot
,因此使用 mod_rewrite
更改 DocumentRoot 变量并不能修复它。
I have an odd situation where I want to have the URLs app1.example.com
, example.com
and *.example.com
all using a different virtual host. This is what I have (excluding example.com
because it just makes it messier).
<VirtualHost *>
ServerName app1.example.com
ServerAlias app1.example.com
DocumentRoot = /var/www/app1
# Other configuration for this app here
</VirtualHost>
<VirtualHost *>
ServerName wildcard.example.com
ServerAlias *.example.com
DocumentRoot = /var/www/wildcard
# other configuration for this app here
</VirtualHost>
The problem is that they conflict. Whichever one is listed first wins out. How can I host both a wildcard virtualhost and a specific one?
Note: I'm not just changing DocumentRoot
in the config, so using mod_rewrite
to change the DocumentRoot variable does not fix it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应该管用。 如果您没有获得显式匹配,第一个条目将成为默认条目。 因此,如果您让 app.otherexample.com 指向它,那么它将被捕获为 app1.example.com。
Should work. The first entry will become the default if you don't get an explicit match. So if you had app.otherexample.com point to it, it would be caught be app1.example.com.
通配符只能在
ServerAlias
中使用,而不能在ServerName
中使用。 有件事让我难住了。对于您的用例,以下内容应该足够了
Wildcards can only be used in the
ServerAlias
rather than theServerName
. Something which had me stumped.For your use case, the following should suffice
这也适用于 https 需要一个解决方案来制作项目目录,就是这样。 因为chrome不喜欢非ssl,所以不再使用免费ssl。 注意:我的 Web 服务器在 Windows 10 上是 Wamp64,因此我不会使用此配置,因为存在变量,除非您使用 wamp。
This also works for https needed a solution to making project directories this was it. because chrome doesn't like non ssl anymore used free ssl. Notice: My Web Server is Wamp64 on Windows 10 so I wouldn't use this config because of variables unless your using wamp.