Apache2 NameVirtualHost *:80 has no VirtualHosts Error and Solution

by on October 27, 2010 · 16 comments· LAST UPDATED December 7, 2010

in

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 16 comments… read them below or add one }

1 Alok Khode January 7, 2011 at 6:04 am

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.

Reply

2 huntsvillepr September 30, 2011 at 11:54 am

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

Reply

3 saurabh October 16, 2011 at 1:16 am

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

Reply

4 saurabh October 16, 2011 at 1:18 am

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

Reply

5 toto March 12, 2012 at 3:51 pm

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

Reply

6 WebDeveloper March 18, 2012 at 2:23 am

Thanks for the write up

Reply

7 whatever October 11, 2012 at 9:59 pm

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 !

Reply

8 Chris December 29, 2012 at 12:38 am

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.

Reply

9 Victor January 16, 2013 at 10:58 pm

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.

Reply

10 Victor January 16, 2013 at 10:59 pm

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

Reply

11 whatever January 17, 2013 at 7:53 am

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

Reply

12 Victor January 17, 2013 at 11:59 am

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.

Reply

13 arnaldo March 11, 2013 at 8:56 pm

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

Reply

14 Edward Welbourne July 21, 2013 at 2:57 pm

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

Reply

15 Mike October 19, 2013 at 12:38 am

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.

Reply

16 Waqar July 25, 2014 at 10:04 am

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

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , ,

Previous Faq:

Next Faq: