Apache2 报错NameVirtualHost :80 has noVirtualHosts

时间:2019-11-20 08:54:17  来源:igfitidea点击:

每次在启动Apache 2服务器并收到以下警告时:

[warn] NameVirtualHost *:80 has no VirtualHosts

NameVirtualHost指令是配置基于名称的虚拟主机所必需的。您需要编辑Apache配置文件httpd.conf或apache2.conf,输入:

# vi httpd.conf

查找如下所示的行:

<VirtualHost *>

替换如下:

NameVirtualHost *:80
<VirtualHost *:80>

保存并关闭文件。这是示例配置文件:

# My Virtual Hosts Config File for two Domains
NameVirtualHost *:80
 
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/local/docs/theitroadtech.com"
    ServerName www.theitroadtech.com
    ServerAlias theos.in
    ErrorLog "/var/log/theos.in-error_log"
    CustomLog "/var/log/theos.in-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>

保存并关闭文件。

最后,重新启动Apache:

# /etc/init.d/apache2 restart

或者:

# service httpd restart