Apache Warning – How to Fix ‘NameVirtualHost *:80 Has No VirtualHosts’ Warning

apache-2.2linux

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?

Best Answer

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.