67

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?

Peter Mortensen
  • 2,318
  • 5
  • 23
  • 24
Kit Roed
  • 773
  • 1
  • 6
  • 7

7 Answers7

52

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.

Vineet
  • 3
  • 2
Dave Cheney
  • 18,567
  • 8
  • 49
  • 56
51

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.

Ivan
  • 3,172
  • 4
  • 25
  • 34
  • 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 03:10
9

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.

3

You have a NameVirtualHost without a matching VirtualHost entry.

This is typically not fatal, just an informative error.

Dominic Eidson
  • 421
  • 4
  • 5
3

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

derobert
  • 1,308
  • 12
  • 22
2

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!

Peter Mortensen
  • 2,318
  • 5
  • 23
  • 24
2

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>

Mo01
  • 121
  • 1