我正在尝试将另一个虚拟主机添加到现有主机列表 (/etc/apache2/sites-availible/default)。以下是当前设置的部分副本:
<VirtualHost *> (<-- currently working)
ServerAdmin [email protected]
Servername nyenrodejazznight.nl
DocumentRoot /home/nrjazznight/html
<Directory "/home/nrjazznight/html">
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *> (<-- added and not working)
ServerAdmin [email protected]
ServerName ncvlustrum.nl
ServerAlias www.ncvlustrum.nl
DocumentRoot /home/lustrum/html
<Directory "/home/lustrum/html">
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我希望当我从现有设置中复制设置并将其用于新设置时,它能够正常工作。然而,这导致了以下问题:A. 新网站在内部重定向到 Apache 的默认网站,B. ncvlustrum.nl 在外部正常运行,但 www.ncvlustrum.nl 被重定向到默认页面(与 A 相同)。其余网站都正常运行(6 个网站中的几个),设置看起来与我添加的设置一样。我遗漏了什么吗?
先感谢您!
附加信息:
ncv:/home/robbert# clear
ncv:/home/robbert# source /etc/apache2/envvars ; /usr/sbin/apache2 -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:* is a NameVirtualHost
default server ncv.campus.nyenrode.nl (/etc/apache2/sites-enabled/000-default:2)
port * namevhost ncv.campus.nyenrode.nl (/etc/apache2/sites-enabled/000-default:2)
port * namevhost nyenroderally.nl (/etc/apache2/sites-enabled/000-default:129)
port * namevhost hvtuinfeest.nl (/etc/apache2/sites-enabled/000-default:140)
port * namevhost nyenrodejazznight.nl (/etc/apache2/sites-enabled/000-default:151)
port * namevhost ncvlustrum.nl (/etc/apache2/sites-enabled/000-default:162)
port * namevhost nieuwecompagnievanverre.nl (/etc/apache2/sites-enabled/000-default:174)
port * namevhost checkout.nieuwecompagnievanverre.nl (/etc/apache2/sites-enabled/000-default:185)
port * namevhost rugby.nyenrode.nl (/etc/apache2/sites-enabled/000-default:196)
port * namevhost dezilverenrijder.nl (/etc/apache2/sites-enabled/000-default:207)
port * namevhost www.dezilverenrijder.nl (/etc/apache2/sites-enabled/000-default:218)
port * namevhost zilverenrijder.nl (/etc/apache2/sites-enabled/000-default:229)
port * namevhost www.zilverenrijder.nl (/etc/apache2/sites-enabled/000-default:240)
port * namevhost ondernemend.nyenrode.nl (/etc/apache2/sites-enabled/000-default:251)
port * namevhost ncv.campus.nyenrode.nl (/etc/apache2/sites-enabled/000-default.save:2)
port * namevhost www.nyenroderally.nl (/etc/apache2/sites-enabled/000-default.save:73)
port * namevhost ncv.campus.nyenrode.nl (/etc/apache2/sites-enabled/000-default.save.1:2)
port * namevhost www.nyenroderally.nl (/etc/apache2/sites-enabled/000-default.save.1:82)
port * namevhost www.hvtuinfeest.nl (/etc/apache2/sites-enabled/000-default.save.1:93)
port * namevhost www.nyenrodejazznight.nl (/etc/apache2/sites-enabled/000-default.save.1:104)
port * namevhost ncv.campus.nyenrode.nl (/etc/apache2/sites-enabled/000-default.save.2:2)
port * namevhost nyenroderally.nl (/etc/apache2/sites-enabled/000-default.save.2:129)
port * namevhost hvtuinfeest.nl (/etc/apache2/sites-enabled/000-default.save.2:140)
port * namevhost nyenrodejazznight.nl (/etc/apache2/sites-enabled/000-default.save.2:151)
port * namevhost ncvlustrum.nl (/etc/apache2/sites-enabled/000-default.save.2:162)
port * namevhost nieuwecompagnievanverre.nl (/etc/apache2/sites-enabled/000-default.save.2:174)
port * namevhost checkout.nieuwecompagnievanverre.nl (/etc/apache2/sites-enabled/000-default.save.2:185)
port * namevhost rugby.nyenrode.nl (/etc/apache2/sites-enabled/000-default.save.2:196)
port * namevhost dezilverenrijder.nl (/etc/apache2/sites-enabled/000-default.save.2:207)
port * namevhost www.dezilverenrijder.nl (/etc/apache2/sites-enabled/000-default.save.2:218)
port * namevhost zilverenrijder.nl (/etc/apache2/sites-enabled/000-default.save.2:229)
port * namevhost www.zilverenrijder.nl (/etc/apache2/sites-enabled/000-default.save.2:240)
port * namevhost ondernemend.nyenrode.nl (/etc/apache2/sites-enabled/000-default.save.2:251)
Syntax OK
ncv:/home/robbert# a2ensite ncvlustrum.nl
ERROR: Site ncvlustrum.nl does not exist!
ncv:/home/robbert# pico /etc/apache2/ports.conf
GNU nano 2.0.7 File: /etc/apache2/ports.conf
Listen 80
Listen 443
答案1
由于您已将虚拟主机指定为<VirtualHost *>
,因此您需要使您的NameVirtualHost
指令匹配;您需要:
NameVirtualHost *
默认情况下,Debian 中有一个NameVirtualHost *:80
指令ports.conf
,它不适用于这些虚拟主机 - 将其更改为与您的虚拟主机匹配,您就可以开始了。正如 stew 在评论中提到的,您可以使用该-S
选项确认情况确实如此。
编辑:根据您的附加信息,看起来您有两个副本正在加载(并且竞争成为服务请求的副本);/etc/apache2/sites-enabled/000-default.save.2:162
和/etc/apache2/sites-enabled/000-default:162
。
似乎是.save
一个备份文件;将其从中取出sites-enabled
,因为其中的所有内容都是实时配置。然后确保在进行必要的更改后重新启动 Apache。