【问题标题】:Wildcard subdomain not using correct conf file通配符子域未使用正确的 conf 文件
【发布时间】: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 配置是不够的。
  • 感谢您的帮助,但不幸的是它仍然忽略它。

标签: apache subdomain wildcard


【解决方案1】:

将文件名从 shared.conf 更改为 000-shared.conf

为 000-shared.conf 使用下面的配置

<VirtualHost *:80>

        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/shared

        <Directory /var/www/shared>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
                RewriteEngine On
        </Directory>
       

</VirtualHost>

【讨论】:

    猜你喜欢
    • 2013-03-23
    • 2012-11-12
    • 1970-01-01
    • 2020-08-23
    • 1970-01-01
    • 2020-05-18
    • 2014-03-17
    • 2020-10-03
    • 1970-01-01
    相关资源
    最近更新 更多