Apache2 NameVirtualHost *:80没有VirtualHosts错误和解决方案

时间:2020-01-09 10:37:11  来源:igfitidea点击:

每当我尝试在UNIX/Linux下启动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/theos.in"
    ServerName www.theos.in
    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