Apache: [warn] _default_ VirtualHost overlap on port 80, the first has precedence Error and Solution

Question:I'm using Apache 2 to host multiple site on a single host using Apache name based VirtualHost feature. However, Apache is displaying lots of warning as follows:

Performing sanity check on apache22 configuration:
[Portal Oct 05 06:59:34 2008] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Portal Oct 05 06:59:34 2008] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Portal Oct 05 06:59:34 2008] [warn] NameVirtualHost 81.aaa.www.yyy:80 has no VirtualHosts
Syntax OK
Stopping apache22.
Waiting for PIDS: 14968.
Syntax OK
Starting apache22.
[Portal Oct 05 06:59:36 2008] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Portal Oct 05 06:59:36 2008] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Portal Oct 05 06:59:36 2008] [warn] NameVirtualHost 81.aaa.www.yyy:80 has no VirtualHosts

How do I fix this warning and host multiple websites under UNIX / Linux Apache 2 webserver?

Answer: The NameVirtualHost directive is a required to configure name-based virtual hosts. Add this to your httpd.conf file to fix this issue. Open httpd.conf file:
# vi httpd.conf
Add NameVirtualHost as follows:
NameVirtualHost *:80
OR add server IP
NameVirtualHost 202.54.1.1:80
Save and close the file. Restart httpd web server under RHEL / Red Hat / Fedora / CentOS Linux:
# service httpd restart
OR type the following to restart Apache 2 under Debian / Ubuntu Linux:
# /etc/init.d/apache2 restart

Sample Apache 2 Virtual hosting configuration

If you want to maintain multiple domains/hostnames on your machine you can setup VirtualHost containers for them. Most configurations use only name-based virtual hosts so the server doesn't need to worry about IP addresses. This is indicated by the asterisks in the directives below.

# 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>
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 6 comments… read them below or add one }

1 4F2E4A2E 02.04.09 at 11:37 pm

is not working for me… really dont know why… its always taking the first entry…

my domain provider:
-----------halbgasse.at:
http://80.108.98.115
-----------hebron.at:
http://80.108.98.115

—————/etc/apache2/sites-available:

NameVirtualHost *:80

    ServerAdmin webmaster@halbgasse.at
    DocumentRoot "/var/www/halbgasse"
    ServerName http://www.halbgasse.at
    ServerAlias halbgasse.at
    ErrorLog "/home/www/halbgasse_error_log"
    CustomLog "/home/www/halbgasse_in-access_log" common

    ServerAdmin webmaster@hebron.at
    DocumentRoot "/var/www/hebron"
    ServerName http://www.hebron.at
    ServerAlias hebron.at
    ErrorLog "/home/www/hebron_error_log"
    CustomLog "/home/www/hebron_access_log" common

-------------------------------------------------------------
2 mnorland 02.19.09 at 8:35 pm

The NameVirtualHost *:80 directive should go in your httpd.conf – sites available is generally symlinks of the actual virtual hosts.

3 freelancer 03.02.09 at 5:37 am

Thanks a lot.
NameVirtualHost *:80

It’s very usefull

4 napolik 04.24.09 at 5:53 am

Thanks. NameVirtualHost *:80 help with all my problems.

PS Sorry for my English =)

5 Seth 05.02.09 at 2:11 pm

Yup, needed this reminder again when I migrated all my sites to a new VPS :)

6 xmen 05.13.09 at 6:24 pm

# My Virtual Hosts Config File for Two Domains
NameVirtualHost *:80

ServerAdmin webmaster@theos.in
DocumentRoot “/usr/local/docs/theos.in”
ServerName http://www.theos.in
ServerAlias theos.in
ErrorLog “/var/log/theos.in-error_log”
CustomLog “/var/log/theos.in-access_log” common

ServerAdmin webmaster@nixcraft.com
DocumentRoot “/usr/local/docs/nixcraft.com”
ServerName http://www.nixcraft.com
ServerAlias nixcraft.com
ErrorLog “/var/log/nixcraft.com-error_log”
CustomLog “/var/log/nixcraft.com-access_log” common

When I configure the same file , I have a problem. I used Firefox, everytime I type http://www.theos.in or http://www.nixcraft.com, I only see mainpage (theos.in), no nixcraft.com

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

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

Previous post: Edit a File When You Are Viewing It Using more / less Command

Next post: PF Firewall Open FTP Port 21 (PASSIVE Configuration)