Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

When my Ubuntu Apache server (Apache 2) starts up I get a warning message that reads:

[warn] NameVirtualHost *:80 has no VirtualHosts

However, the web server is working fine. What might I have wrong in my site's configuration to make it give me this warning?

The configuration file in question (located in /etc/apache2/sites-available) reads like (details removed for brevity)

<VirtualHost *>
    <Location /mysite>
        # Configuration details here...
    </Location>

    # Use the following for authorization.
    <LocationMatch "/mysite/login">
        AuthType Basic
        AuthName "My Site"
        AuthUserFile /etc/sitepasswords/passwd
        Require valid-user
    </LocationMatch>
</VirtualHost>

Could the fact that I'm using <Location> be a part of the problem?

share|improve this question
add comment

7 Answers

up vote 49 down vote accepted

Change

<VirtualHost *>

to read

<VirtualHost *:80>

Or its (NameVirtualHost *:80) added twice in your apache2 Confing file. ( By Default its added in ports.conf file )

This should clear the error.

Aside: you shouldn't ignore this error. Apache's config, especially when globbing virtual hosts (eg Include /etc/httpd/vhosts.d/*) is not stable. That means you don't control the order of loading the hosts explicitly so the default vhost for an IP becomes the one that is loaded first, which can lead to unintended consequences.

One example of this is the default vhost for an IP will also be available on that IP, rather than its name. This can cause information to leak onto google referring to your sites IP rather than name, which can be confusing for customers.

The NameVirtualHost error above can be a hint that apache has loaded things in a non optimal way, so you shouldn't ignore it.

share|improve this answer
1  
Nailed it! Thanks for clearing that up! –  Kit Roed May 12 '09 at 16:19
4  
You can set the default vhost like this: <VirtualHost _default_ thehostname.com> –  Amy B Oct 10 '10 at 12:49
add comment

That could be because you have the NameVirtualHost directive in more than one place.

I don't know about other distributions, but in Ubuntu/Debian, Apache's configuration is split in several files, so you'd have to check where the duplication is (httpd.conf, apache2.conf, ports.conf, conf.d/*).

Oh, and I just found this great resource with more information: Common Apache Misconfigurations.

share|improve this answer
3  
The link you gave looks like a great resource for trying to understand the nuances of Apache config files. Thanks! –  Kit Roed Apr 30 '09 at 18:35
4  
Thanks! This was my problem - I had created a virtual.conf for NameVirtualHost, not knowing it was already in ports.conf –  rcampbell Oct 23 '09 at 14:13
    
Thanks - Same problem here in a ubuntu server default configuration: ports.conf contains NameVirtualHost :80 and should not be repeated in the sites-enabled/ config files! –  DrSAR Apr 30 '11 at 23:22
1  
In my case, this issue was because ubuntu had NameVirtualHost *:80 both in ports.conf and in conf.d/virtualhosts, which appears to be an Ubuntu bug. –  fluffy Jul 30 '12 at 3:10
    
amazing!!! thanks a lot –  In God I Trust Sep 6 '12 at 18:54
add comment

You have a NameVirtualHost without a matching VirtualHost entry.

This is typically not fatal, just an informative error.

share|improve this answer
add comment

It's because your NameVirtualHost line has a port number on it (:80), but your VirtualHost sections don't.

share|improve this answer
add comment

On a Debian/Lenny box: In /etc/apache2/ports.conf there is an additional NameVirtualHost statement - that could be the cause for this issue (there is also the same statement in /etc/apache2/sites-available/default). I commented that statement and the error disappered.

share|improve this answer
add comment

I have the same problem, but I disable the default site of Apache in some moment. I type something like

# a2dissite default

After I try to restart Apache 2, I receive this message:

"[warn] NameVirtualHost *:80 has no VirtualHosts"

Then I enable the 'default' site of Apache 2 again and everything works again, the command used is:

# a2ensite default

That's all folks!

share|improve this answer
    
This has been the best advice. –  jini Aug 26 '11 at 4:58
add comment

AS Rune mentions, on Debian systems NameVirtualHost appears in many files - ports.conf, conf.d/virtual.conf and possibly your own conf files int sites-available

Make sure it exists in one place as NameVirtualHost *:80 (mine is in conf.d/virtual.conf) and the warnings should go.

As mentioned you also need to make the VirtualHost direction for each site-available have this format <VirtualHost *:80>

share|improve this answer
add comment

protected by Community Jun 4 '11 at 10:05

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.