Apache2 NameVirtualHost *:80 has no VirtualHosts Error and Solution

Posted on in Categories , last updated December 7, 2010

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>
 
<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
</VirtualHost>

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

18 comment

  1. Virtual Host refers to the practice of running more than one web site (such as http://www.company1.com and http://www.company2.com) on a single machine. Virtual hosts can be “IP-based”, meaning that you have a different IP address for every web site, or “name-based”, meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user. Using virtual hosts, host several domains with a single web server. In this way, save the costs and administration workload for separate servers for each domain.

  2. I have a fedora 14 server from godaddy. my website does not show up in the browser. I have 4 websites on this server. i restarted apache and get the no virtual host error.

    I typed in # vi httpd.conf
    and the screen was blank

    What is the solution

    thanks

  3. This solution simply doesn’t work for me. I have 3 different virtual hosts on my server, and these instructions do not help me. This is what it looks like for me:

    NameVirtualHost *:80

    DocumentRoot /var/www/
    ServerName [redacted]
    ServerAlias http://www.[redacted]

    DocumentRoot /var/[redacted]/
    ServerName [redacted]
    ServerAlias http://www.[redacted]

    DocumentRoot /var/[redacted]/
    ServerName [redacted]
    ServerAlias http://www.[redacted]

    After I run “sudo /etc/init.d/apache2 restart”, it says “[warn] NameVirtualHost *:80 has no VirtualHosts”. The problem must lie somewhere else. I’m using an Ubuntu 12.10 system.

        1. That was not the problem. (The comment system here messed up my comment because I used angle brackets.) I did have the different VirtualHost declarations in separate scopes. The problem was instead that I had declared “NameVirtualHost *:80” twice, once in apache2.conf and once in ports.conf.

  4. My Apache config contains no wild-carded VirtualHost or NameVirtualHost entries. It’s an entirely local web-server, purely for local use, so has
    NameVirtualHost 127.0.0.1:80

    All the same, I was getting this error message.
    Eventually I found the culprit: there’s *also* a NameVirtualHost *:80 line in ports.conf, distributed as part of the default Debian package. Commenting out that line gets rid of the warning message.

    Note on file locations: for the Debian package (used by Ubuntu) the configuration is all under /etc/apache2/. The site-specific configuration files are in sites-available/ with symlinks from sites-enabled/ determining which available configurations are active. The culprit in this case is /etc/apache2/ports.conf (and you can use whatever editor you happen to prefer, be it vi, emacs, pico, nano or some fiendish combination of head, tail and echo).

    1. If you have NameVirtualHost in both httpd.conf and in ports.conf, commenting out either one of those gets rid of the warning message. After thinking about it for a while, I decided to comment out the line in httpd.conf, because ports.conf was part of installation, and httpd.conf was written entirely by me. I don’t know whether that was the right decision, though.

  5. I made the following changes in my httpd.conf file and restarted apache and still got the same error message : Starting httpd: [Sun Apr 03 13:35:29 2016] [warn] NameVirtualHost puppetmaster.xyz.com:80 has no VirtualHosts,
    Is there something Im not doing right?

    NameVirtualHost *:80

    # ServerAdmin [email protected]
    DocumentRoot /var/www/html/xyz
    ServerName wiki.xyz.com
    # ErrorLog logs/dummy-host.example.com-error_log
    # CustomLog logs/dummy-host.example.com-access_log common

  6. The warning says, that there is an entry in your ports.conf that has no Virtual Hosts assigned to it.
    You can remove the NameVirtualHost and the Listen entries from your ports.conf and the Warning will be gone.

Leave a Comment