我的 VirtualHosts 重叠,我的 NameVirtualHost 没有 VirtualHosts

cwa*_*ole 4 centos virtualhost apache-2.2

我认为问题标题几乎说明了问题。重新启动 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
Run Code Online (Sandbox Code Playgroud)

两个 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>
Run Code Online (Sandbox Code Playgroud)

显然,我遗漏了一些明显影响这个结果的东西,但我不知道是什么。(显然,两个站点目前都指向同一页面)

(不确定这是否重要,但我使用 CentOS)。

解决方案

非常感谢下面 Mike Diehn 的解决方案,但它与他建议的解决方案略有不同。

我跑了:

/usr/sbin/httpd -t -D DUMP_VHOSTS
Run Code Online (Sandbox Code Playgroud)

我得到了

[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
Run Code Online (Sandbox Code Playgroud)

注意!!!!!!!!!!!? 那是因为我不小心从其他地方复制了它。它吞噬了一切,使其无法正常工作。

小智 5

您确定您的 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
Run Code Online (Sandbox Code Playgroud)