NameVirtualHost *:80 has no VirtualHosts
Asked Answered
W

2

39

I have two domain names, two ssl certs and two ip addresses. I am trying to configure my apache virtualhost files for them.

First, i commented out all instances of "NameVirtualHost" and "Listen" for ports 80 and 443. Then i did the following with my virtual hosts files.

VirtualHost file for domain1:

NameVirtualHost 1.1.1.1:80
Listen 1.1.1.1:80
Listen 1.1.1.1:443
<VirtualHost 1.1.1.1:80>
    ServerName domain1.com
    ...
</VirtualHost>
<VirtualHost 1.1.1.1:443>
    ...
</VirtualHost>

VirtualHost file for domain2:

NameVirtualHost 2.2.2.2:80
Listen 2.2.2.2:80
Listen 2.2.2.2:443
<VirtualHost 2.2.2.2:80>
    ServerName domain2.com
    ...
</VirtualHost>
<VirtualHost 2.2.2.2:443>
    ...
</VirtualHost>
Whipperin answered 23/8, 2011 at 18:16 Comment(1)
NameVirtualHost has been deprecated and it's no longer required.Subheading
J
32

Somewhere in your configuration, probably in the Apache default configuration file (I think /etc/apache2/httpd.conf in Ubuntu? someone can correct me in the comments), is a line that looks like:

NameVirtualHost *:80

# Also
Listen 80
Listen 443

Comment them out, and in your VirtualHost configuration files, add:

Listen 111.111.111.111:80
Listen 222.222.222.222:80
# If also using SSL
Listen 111.111.111.111:443
Listen 222.222.222.222:443

NameVirtualHost 111.111.111.111:80
NameVirtualHost 222.222.222.222:80

In many default Apache configurations, the Listen and NameVirtualHost directives are supplied with wildcards, or globally to apply to all network interfaces. Since you're using multiple IP addresses bound to different configurations, you need to be more specific in your config directives than your distribution's default config file.

Jabot answered 23/8, 2011 at 18:20 Comment(8)
/etc/apache2/httpd.conf is empty. /etc/apache2/httpd.conf doesn't have "NameVirtualHost" or "Listen". Still looking.Whipperin
@Whipperin try grep -r Listen /etc/apache2 and grep -r NameVirtualHost /etc/apache2Jabot
confirming understanding... comment out the "NameVirtualHost" line and the "Listen" lines. I will now update the original post with my understanding of how to modify the virtual host files. Thanks.Whipperin
@Whipperin Yes, correct. Comment out the original directives and add your new onesJabot
@Whipperin If there are no more Listen directives, something else may already be on port 80 for the 222 IP.Jabot
if you have the time, see the update above related to your last comment.Whipperin
I posted the results to your last comment.Whipperin
@Whipperin I'm kinda running out of ideas. Both addresses are clearly in use by the same apache process. I'm going to vote to move this to serverfault, and hopefully others will do the same so it gets migrated.Jabot
S
42

I had ignored the same error for the 2 months I have had an Ubuntu server. I found this post nicely solved the error. Thank you Michael!. As did you Jay, I found the culprit at /etc/apache2/ports.conf . I tried simply this:

# NameVirtualHost *:80
I only commented out that line and no other changes and no more

"NameVirtualHost *:80 has no VirtualHosts"

Sculpture answered 8/1, 2012 at 21:25 Comment(0)
J
32

Somewhere in your configuration, probably in the Apache default configuration file (I think /etc/apache2/httpd.conf in Ubuntu? someone can correct me in the comments), is a line that looks like:

NameVirtualHost *:80

# Also
Listen 80
Listen 443

Comment them out, and in your VirtualHost configuration files, add:

Listen 111.111.111.111:80
Listen 222.222.222.222:80
# If also using SSL
Listen 111.111.111.111:443
Listen 222.222.222.222:443

NameVirtualHost 111.111.111.111:80
NameVirtualHost 222.222.222.222:80

In many default Apache configurations, the Listen and NameVirtualHost directives are supplied with wildcards, or globally to apply to all network interfaces. Since you're using multiple IP addresses bound to different configurations, you need to be more specific in your config directives than your distribution's default config file.

Jabot answered 23/8, 2011 at 18:20 Comment(8)
/etc/apache2/httpd.conf is empty. /etc/apache2/httpd.conf doesn't have "NameVirtualHost" or "Listen". Still looking.Whipperin
@Whipperin try grep -r Listen /etc/apache2 and grep -r NameVirtualHost /etc/apache2Jabot
confirming understanding... comment out the "NameVirtualHost" line and the "Listen" lines. I will now update the original post with my understanding of how to modify the virtual host files. Thanks.Whipperin
@Whipperin Yes, correct. Comment out the original directives and add your new onesJabot
@Whipperin If there are no more Listen directives, something else may already be on port 80 for the 222 IP.Jabot
if you have the time, see the update above related to your last comment.Whipperin
I posted the results to your last comment.Whipperin
@Whipperin I'm kinda running out of ideas. Both addresses are clearly in use by the same apache process. I'm going to vote to move this to serverfault, and hopefully others will do the same so it gets migrated.Jabot

© 2022 - 2024 — McMap. All rights reserved.