【发布时间】:2021-09-04 09:28:18
【问题描述】:
我的设置如下:
所有指向服务器的子域
sub1.example.com 应该加载 /var/www/sub1
sub2.example.com 应该加载 /var/www/sub2
任何随机子域都应该加载 /var/www/shared
问题是 shared.conf 文件被忽略,而是使用 sub1(或我移至 .conf 文件列表开头的任何一个)。
这是运行ls -lv后按顺序排列的我的conf文件
sub1.conf
sub2.conf
shared.conf
sub1.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName sub1.example.com
ServerAlias sub1.example.com
<Directory /var/www/sub1/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/sub1
</VirtualHost>
sub2.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName sub2.example.com
ServerAlias sub2.example.com
<Directory /var/www/sub2/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/sub2
</VirtualHost>
shared.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerAlias *.example.com
<Directory /var/www/shared/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/shared
</VirtualHost>
我也尝试将随机子域添加到服务器名称的 shared.conf 文件中,即
ServerName shared-random.example.com
还有
ServerName *.example.com
我也确定要重启 apache。
所以当我放入任何子域时,例如blabla.example.com 它总是转到 sub1.conf。
我知道行为是默认为第一个,但前提是没有匹配项。为什么 shared.conf 不被视为匹配项?
【问题讨论】:
-
尝试在 shared.conf 中添加
ServerName *.example.com。只有ServerAlias配置是不够的。 -
感谢您的帮助,但不幸的是它仍然忽略它。