Apache:[警告] default VirtualHost在端口80上重叠,第一个优先级错误和解决方案

时间:2020-01-09 10:44:07  来源:igfitidea点击:

问题:我使用Apache 2通过基于Apache名称的VirtualHost功能在单个主机上托管多个站点。
但是,Apache显示很多警告,如下所示:

Performing sanity check on apache22 configuration:
[Portal Oct 05 06:59:34 2008] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Portal Oct 05 06:59:34 2008] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Portal Oct 05 06:59:34 2008] [warn] NameVirtualHost 81.aaa.www.yyy:80 has no VirtualHosts
Syntax OK
Stopping apache22.
Waiting for PIDS: 14968.
Syntax OK
Starting apache22.
[Portal Oct 05 06:59:36 2008] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Portal Oct 05 06:59:36 2008] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Portal Oct 05 06:59:36 2008] [warn] NameVirtualHost 81.aaa.www.yyy:80 has no VirtualHosts

如何解决此警告并在UNIX/Linux Apache 2 Web服务器下托管多个网站?
答案:NameVirtualHost指令是配置基于名称的虚拟主机所必需的。
将此添加到您的httpd.conf文件以解决此问题。
打开httpd.conf文件:

# vi httpd.conf

添加NameVirtualHost,如下所示:

NameVirtualHost *:80

或者添加服务器IP

NameVirtualHost 192.54.1.1:80

保存并关闭文件。
在RHEL/Red Hat/Fedora/CentOS Linux下重新启动httpd Web服务器:

# service httpd restart

或者执行以下命令以在Debian/Ubuntu Linux下重新启动Apache 2:

# /etc/init.d/apache2 restart

示例Apache 2虚拟主机配置

如果要在计算机上维护多个域/主机名,则可以为其设置VirtualHost容器。
大多数配置仅使用基于名称的虚拟主机,因此服务器无需担心IP地址。
这由以下指令中的星号表示。

# My Virtual Hosts Config File for Two Domains
NameVirtualHost *:80
 
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/local/docs/theitroad.com"
    ServerName www.theitroad.com
    ServerAlias theitroad.com
    ErrorLog "/var/log/theitroad.com-error_log"
    CustomLog "/var/log/theitroad.com-access_log" common
</VirtualHost>
 
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/local/docs/theitroad.com"
    ServerName www.theitroad.com
    ServerAlias theitroad.com
    ErrorLog "/var/log/theitroad.com-error_log"
    CustomLog "/var/log/theitroad.com-access_log" common
</VirtualHost>