• 4

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

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

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


When start Apache web server or restart the HTTPD service on web host, the following warning message may appears on console or error log, even though Apache HTTP service can still startup and running fine without error.

[warn] NameVirtualHost *:80 has no VirtualHosts

where * can be asterisk itself (*), hostname or IP address.

Luckily the message is just a warning message and does not affect the functionality of web server, and hence the websites hosted on the server can still be served properly. The possible cause for this problem’s symptom is incorrect use of NameVirtualHost.

When the server, dedicated or virtual private server web host, has only one IP address, websites are hosted by Apache via name based virtual hosting. In this case, there should be only one NameVirtualHost been defined. For example,

NameVirtualHost *:80
<VirtualHost *:80>
servername host
serverPath /public_html/
DocumentRoot /public_html/

The name of one or more virtual hosts (websites’ domain name) is defined by “servername” directive. So if you have more than one websites hosted on a single IP address, you will have one NameVirtualHost declaration and many VirtualHost sections to configure those domains.

Beside, try at best to use IPs or * for the NameVirtualHost and <VirtualHost> directives. In some cases, where the website is assigned a dedicated IP address where only one virtual host is declared, the NameVirtualHost can even be dropped.

For more example on how VirtualHost supposed to be setup, visit Apache 2.2 documentation or Apache 1.3 documentation (more common version of Apache used currently as most control panel such as cPanel comes with this, although it’s going to be upgraded in cPanel 11).

  • 0
Reply Report

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

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

  • 0
Reply Report


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

  • 0
Reply Report