Apache2 NameVirtualHost *:80 has no VirtualHosts Error and Solution

last updated in Categories ,

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 webmaster@theos.in
    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 webmaster@nixcraft.com
    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: Vivek Gite

The author is the creator of nixCraft 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.

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


  3. People learn basics !

    It’s not vi or nano and it’snot /etc/apache2/httpd.conf or /etc/apache2/apache2.conf.

    It’s whatever is right for the DISTRIBUTION you use !

  4. simply doesn’t work as it is not closed? This on doesn’t work on CentOS 6. If we close it with , the httpd service doesn’t throw an error on restart at least.

  5. 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.

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

    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.

  7. Excellent guide as usual.
    I had the Name** line in two places!
    @TOTO, difference in OS. debian based have apache2 AFAIK and centos, httpd.

  8. 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 webmaster@dummy-host.example.com
    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

  9. 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.

    Still, have a question? Get help on our forum!