Apache2 通配符 + 静态子域

Apache2 wildcard + static subdomain

我希望将所有子域的流量定向到一个目录,仅将一个特定子域的流量定向到另一个目录。

<VirtualHost beta.home.lan:80>
    ServerName beta.home.lan
    DocumentRoot /var/www/beta
</VirtualHost>

<VirtualHost *:80>
    ServerName beta.home.lan
    DocumentRoot /var/www/others
</VirtualHost>

它接缝第一个虚拟服务捕获所有流量。 我做错了什么? 谢谢!

http://httpd.apache.org/docs/2.2/en/mod/core.html#servername:

“If you are using name-based virtual hosts, the ServerName inside a section specifies what hostname must appear in the request's Host: header to match this virtual host.”

如果您请求除 beta.home.lan 之外的任何其他内容,则您的两个 VirtualHosts 中的服务器名称都不匹配 – 因此适用,

http://httpd.apache.org/docs/2.2/en/vhosts/name-based.html#using:

“If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.”

在您的第二个 VirtualHost 中使用 ServerAlias

<VirtualHost *:80>
    ServerName beta.home.lan
    DocumentRoot /var/www/beta
</VirtualHost>

<VirtualHost *:80>
    ServerAlias *.home.lan
    DocumentRoot /var/www/others
</VirtualHost>