apache2 ServerAlias 表现出奇怪的行为

apache2 ServerAlias 表现出奇怪的行为

我正在尝试在单个 apache2 服务器上设置两个网站。一个是主站点,另一个是云服务器

第一个在 000-default.conf 中定义:

<VirtualHost *:80>

ServerName www.example.com
ServerAlias example.com

ServerAdmin webmaster@localhost

DocumentRoot /var/www-sites/main/

<Directory  /var/www-sites/main/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    Require all granted
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<Directory "/usr/lib/cgi-bin">                                                                       
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined
ServerSignature On

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

第二个在 100-cloud.conf 中

<VirtualHost *:80>

DocumentRoot /var/www-sites/OwnCloud
ServerName cloud.example.com
ServerAlias www.cloud.example.com

ServerAdmin webmaster@localhost



<Directory  /var/www-sites/OwnCloud>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    Require all granted
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<Directory "/usr/lib/cgi-bin">                                                                       
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

ServerSignature On

现在有一件奇怪的事情:

在此示例中,www.cloud.example.com 转到默认站点(example.com),而不是 cloud.example.com

如果我将第一个 conf 文件的名称更改为 zzz-default.conf,则 www.example.com 将更改为 cloud.example.com

如果我更改文件,则会显示以下内容:

ServerName www.cloud.example.com
ServerAlias cloud.example.com

如果 ServerAlias 不起作用,cloud.example 将被定向到默认值

我做错了什么?在我的其他服务器上,这运行正常。

谢谢

额外信息:输出为apachectl -S

VirtualHost configuration:
*:80                   is a NameVirtualHost
     default server www.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
     port 80 namevhost www.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
             alias example.com
     port 80 namevhost sys.example.com (/etc/apache2/sites-enabled/000-default.conf:50)
     port 80 namevhost cloud.example.com (/etc/apache2/sites-enabled/100-cloud.conf:1)
             alias www.cloud.example.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: ENABLE_USR_LIB_CGI_BIN
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used

答案1

我怀疑您没有NameVirtualHost指令,因为您描述第一个 VirtualHost 接管了第二个。也许您可以通过运行来获取更多信息apachectl -S。如果不是NameVirtualHost缺少指令,请将这些命令的输出添加到您的帖子中。

相关内容