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 goos更改为cloud.example.com

如果我更改文件,所以它说:

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

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

我究竟做错了什么 ? 在我的其他服务器上,这工作得很好。

谢谢

额外的信息: 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 

我会怀疑你没有NameVirtualHost指令,因为你描述了第一个VirtualHost接pipe第二个指令。 也许你可以通过运行apachectl -S得到更多的信息。 如果不是缺lessNameVirtualHost指令,请将这些命令的输出添加到您的文章中。