通配符子域和静态子域的虚拟主机 [英] Virtualhost For Wildcard Subdomain and Static Subdomain

查看:31
本文介绍了通配符子域和静态子域的虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的情况,我想要 URL app1.example.comexample.com*.example.com> 全部使用不同的虚拟主机.这就是我所拥有的(不包括 example.com,因为它只会让它变得更混乱).

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?

注意:我不只是更改配置中的 DocumentRoot,因此使用 mod_rewrite 更改 DocumentRoot 变量并不能修复它.

Note: I'm not just changing DocumentRoot in the config, so using mod_rewrite to change the DocumentRoot variable does not fix it.

推荐答案

<VirtualHost *:80>
  DocumentRoot /var/www/app1
  ServerName app1.example.com
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot /var/www/example
  ServerName example.com
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot /var/www/wildcard
  ServerName other.example.com
  ServerAlias *.example.com
</VirtualHost>

应该可以.如果您没有得到明确的匹配,第一个条目将成为默认值.所以如果你让 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.

这篇关于通配符子域和静态子域的虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆