Apache2 NameVirtualHost *:80 has no VirtualHosts Error and Solution

Whenever I try to star my Apache 2 server under UNIX / Linux and get a warning as follows:

[warn] NameVirtualHost *:80 has no VirtualHosts

How do I fix this problem?

The NameVirtualHost directive is a required to configure name-based virtual hosts. You need edit your Apache configuration file httpd.conf or apache2.conf, enter:
# vi httpd.conf
Find line that read as follows:

<VirtualHost *>

Replace is at follows:

NameVirtualHost *:80
<VirtualHost *:80>

Save and close the file. Here is the sample config file:

# 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 *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/local/docs/nixcraft.com"
    ServerName www.nixcraft.com
    ServerAlias nixcraft.com
    ErrorLog "/var/log/nixcraft.com-error_log"
    CustomLog "/var/log/nixcraft.com-access_log" common

Save and close the file. Finally, restart Apache:
# /etc/init.d/apache2 restart
# service httpd restart

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.