我在 Debian 9 上运行 Apache2 服务器。文件夹中有 2 个虚拟主机配置/etc/apache2/sites-enabled/
。
第一的:
Options FollowSymLinks
<Directory "/srv/">
Options FollowSymLinks ExecCGI
Require all granted
</Directory>
<Directory "/srv">
Options FollowSymlinks ExecCGI
Require all granted
</Directory>
<VirtualHost *:80>
ServerName domain.sk
ServerAlias dev.domain.sk
DocumentRoot /srv/domain.sk/!www
<Directory /srv/domain.sk/!www>
Options Indexes FollowSymlinks ExecCGI
AllowOverride All
</Directory>
</VirtualHost>
第二:
Options FollowSymLinks
<Directory "/home/test/">
Options FollowSymLinks ExecCGI
Require all granted
</Directory>
<VirtualHost *:80>
ServerName domain.sk
ServerAlias test.dev.domain.sk
DocumentRoot /home/test/domain.sk/!www
<Directory /home/test/domain.sk/!www>
Options Indexes FollowSymlinks ExecCGI
AllowOverride All
</Directory>
</VirtualHost>
问题是,如果我去的dev.domain.sk
话好的,但如果我去test.dev.domain.sk
它会显示的内容dev.domain.sk
和不是的内容test.dev.domain.sk
。如果我禁用第一个虚拟主机配置,那么我就会看到的内容test.dev.domain.sk
,因此它看起来像是dev.domain.sk
“覆盖”了test.dev.domain.sk
,我该如何解决?
答案1
问题是您使用了ServerName
两次同名的指令。ServerName
每个虚拟主机都应该是唯一的。在您的示例中不需要ServerAlias
。下面是我所说的一个例子:
<VirtualHost *:80>
ServerName dev.domain.sk
DocumentRoot /srv/domain.sk/!www
<Directory /srv/domain.sk/!www>
Options Indexes FollowSymlinks ExecCGI
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName test.dev.domain.sk
DocumentRoot /home/test/domain.sk/!www
<Directory /home/test/domain.sk/!www>
Options Indexes FollowSymlinks ExecCGI
AllowOverride All
</Directory>
</VirtualHost>