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:

ADVERTISEMENTS

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

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
18 comments… add one
  • Alok Khode Jan 7, 2011 @ 6:04

    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.

  • huntsvillepr Sep 30, 2011 @ 11:54

    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

    • saurabh Oct 16, 2011 @ 1:16

      check your present working directory,
      try this:
      vi /etc/httpd/conf/httpd.conf

  • saurabh Oct 16, 2011 @ 1:18

    also to restart apache try:
    service httpd restart
    or
    /etc/init.d/httpd restart

  • toto Mar 12, 2012 @ 15:51

    Guy, it’s
    nano /etc/apache2/apache2.conf
    not /etc/apache2/httpd.conf like in your post.

  • WebDeveloper Mar 18, 2012 @ 2:23

    Thanks for the write up

  • whatever Oct 11, 2012 @ 21:59

    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 !

  • Chris Dec 29, 2012 @ 0:38

    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.

  • Victor Jan 16, 2013 @ 22:58

    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.

    • Victor Jan 16, 2013 @ 22:59

      And as usual, HTML markup in comments screws up web developer blogs.

      • whatever Jan 17, 2013 @ 7:53

        The problem is your configuration .
        You must wrap different virtual hosts in a
        statement each like in here:
        http://httpd.apache.org/docs/2.2/en/vhosts/examples.html

        • Victor Jan 17, 2013 @ 11:59

          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.

  • arnaldo Mar 11, 2013 @ 20:56

    Check to see if you have NameVirtualHost *:80 twice in you apache confs.

  • Edward Welbourne Jul 21, 2013 @ 14:57

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

    • Mike Oct 19, 2013 @ 0:38

      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.

  • Waqar Jul 25, 2014 @ 10:04

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

  • DNG Apr 3, 2016 @ 17:39

    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

  • be_commerce Oct 13, 2016 @ 11:50

    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 Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.