我认为问题标题几乎说出了问题所在。当我重新启动 httpd 时,我收到以下两个错误:
[Wed Jun 22 13:39:23 2011] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Wed Jun 22 13:39:23 2011] [warn] NameVirtualHost *:80 has no VirtualHosts
我正在包含一个文件,其中只有这一行:
NameVirtualHost *:80
并且两个 VirtualHosts 几乎与此相同:
<VirtualHost *:80>
ServerAdmin webmaster@<other-name>.com
DocumentRoot /var/www
ServerName www.<name>.com
ServerAlias <name>.com *.<name>.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/error_log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/httpd/access_log combined
</VirtualHost>
显然,我忽略了一些明显会影响这一结果的因素,但我不知道是什么。(显然,两个网站目前都指向同一个页面)
(不确定这是否重要,但我使用的是 CentOS)。
解决方案
完全赞赏 Mike Diehn 提供的以下解决方案,但它与他建议的解决方案略有不同。
我跑了:
/usr/sbin/httpd -t -D DUMP_VHOSTS
我得到了
[Wed Jun 22 14:23:20 2011] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Wed Jun 22 14:23:20 2011] [warn] NameVirtualHost *:80 has no VirtualHosts
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 <name-one>.com (/etc/httpd/conf.d/ssl.conf:81)
*:80 www.<name-one>.com (/etc/httpd/conf/sites-enabled/100-default:1)
*:80 www.<name-two>.info (/etc/httpd/conf/sites-enabled/200-info:1)
*:* www.<!!!!!!!!!!!!!!>.com (/etc/httpd/conf/sites-enabled/6-<bad>.com:1)
Syntax OK
注意到了吗!!!!!!!!!!!
?那是因为我不小心从其他地方复制了它。它吞噬了所有内容,导致它无法正常工作。
答案1
你确定你的 NameVirtualHost 指令确实被 Apache “看到”了吗?这是我们经常看到的一个错误
嘿,试试这个命令:
/usr/sbin/apache2ctl -t -D DUMP_VHOSTS
这是我在正常运行的服务器上看到的内容:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:* is a NameVirtualHost
default server loghost.example.com (/etc/apache2/vhosts.d/10_loghost.example.com.conf:4)
port * namevhost loghost.example.com (/etc/apache2/vhosts.d/10_loghost.example.com.conf:4)
port * namevhost netflow.example.com (/etc/apache2/vhosts.d/20_netflow.fluent.com.conf:4)
port * namevhost licensewatch.example.com (/etc/apache2/vhosts.d/40_licensewatch.example.com.conf:8)
Syntax OK