用于子域的虚拟主机覆盖默认的虚拟主机

我在Apache中有两个虚拟主机。 一个默认的处理所有的请求,一个用于特定的子域名。 www目录设置如下:

/var/www /var/www/subdomain 

虚拟主机configuration如下:

 <VirtualHost *:80> DocumentRoot /var/www <Directory /> Options None AllowOverride None </Directory> <Directory /var/www> Options None AllowOverride None Deny from all </Directory> </VirtualHost> <VirtualHost subdomain> ServerName subdomain.domain.com DocumentRoot /var/www/subdomain <Directory /var/www/subdomain> Options None FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost> 

现在我想要任何subdomain.domain.com/var/www/subdomain和任何其他请求被拒绝。 但是当我访问domain.com时,它服务于/var/www/subdomain

感谢有人能告诉我我做错了什么。 谢谢!


运行apache2ctl -S时编辑额外的信息

 /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted) apache2: Could not reliably determine the server's fully qualified domain name, using XX.XXX.XXX.XX for ServerName VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server domain (/etc/apache2/sites-enabled/default:1) port 80 namevhost domain (/etc/apache2/sites-enabled/default:1) port 80 namevhost sub.domain.com (/etc/apache2/sites-enabled/subdomain:1) Syntax OK 

你的问题在这里:

 <VirtualHost subdomain> 

不要这么做,因为它将为那些解决了问题的IP赋予虚拟主机优先权。 它应该是<VirtualHost *:80>匹配你现有的虚拟主机。 ServerName指令是虚拟主机的“名称”应该去的地方。

你还需要一个NameVirtualHost *:80地方,如果你还没有。