VirtualHosts nightmare on SUSE
I’d like to share with time consuming problem I had last days with vHosts on Apache2 on openSuse linux. Maybe my solution will be helpful for someone, cause believe me, it’s was not easy to find solution (especially using “tries and faults” method).
So my point was to create and successful run few vHosts on my newly settled up Apache2 server. So I’ve created this vHost directives in /etc/apache2/vhosts.d/vhosts.conf :
<virtualhost *:80>
ServerAdmin webmaster@somedomain.com
DocumentRoot /srv/www/somedomain
ServerName www.somedomain.com
ServerAlias somedomain.com
</virtualhost>
<virtualhost *:80>
ServerAdmin webmaster@elsedomain.com
DocumentRoot /srv/www/elsedomain
ServerName www.elsedomain.com
ServerAlias elsedomain.com
</virtualhost>
<virtualhost *:80>
ServerAdmin webmaster@otherdomain.com
DocumentRoot /srv/www/otherdomain
ServerName www.otherdomain.com
ServerAlias otherdomain.com
</virtualhost>
After this, I had to also put new statements into /etc/hosts :
127.0.0.1 www.somedomain.com 127.0.0.1 somedomain.com 127.0.0.1 www.elsedomain.com 127.0.0.1 elsedomain.com 127.0.0.1 www.otherdomain.com 127.0.0.1 otherdomain.com
That’s all. Then I’ve restart apache service, by:
apache2ctl restart
and here’s the result (and the problem itself) :
[Wed Jul 25 21:42:59 2007]
[warn] _default_ VirtualHost overlap on port 80, the first has precedence
What does it mean? The first vHost directive was treat as default one, and somehow every second vHost directive was in conflict with the default one. The The result of this conflict was, that after calling conflicted (means not the default ones) host name URL in browser (”elsedomain.com”, “otherdomain.com”) I got the content (main page) of the default host: “somedomain.com”.
So I hope the problem is clear. And here is what also didn’t work out:
* changing vHosts directive to:
<virtualhost *:*>
[...]
</virtualhost>
* changing vHosts directive to:
<virtualhost 127.0.0.1:*>
[...]
</virtualhost>
* changing vHosts directive to:
<virtualhost 127.0.0.1:80>
[...]
</virtualhost>
* changing IP address in /etc/hosts to 127.0.0.2 and vHosts directive to:
<virtualhost 127.0.0.2:80>
[...]
</virtualhost>
What does really help was something else. I’ve to add new line in the top of my vhosts.conf file:
NameVirtualHost 127.0.0.1
and modify all vHosts sections this way:
<virtualhost 127.0.0.1:80>
[...]
</virtualhost>
It was clear for me that “NameVirtualHost” should be there somewhere. Nevertheless, was very hard to find out that for default in Apache2 (or at least in his SUSE10.2 distribution) this directive is gone for default. Changing ‘*’ mark to localhost IP address (127.0.0.1) goes without saying.
So if You have problem with this warning above I’ve notice, my method should be helpful for You.
Greets
Thank you very much for posting how you solved this problem! It helped me to solve a similar problem.
However, with “NameVirtualHost 127.0.0.1″ I got the error message “[error] VirtualHost 127.0.0.1:80 — mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results”
So I used “NameVirtualHost *:80″ (it was the port which was missing here), I assume “127.0.0.1:80″ would have worked to. (Just in case this information might be helpful for anyone)
Komentarz od Micha — 31/08/2007 @ 10:42
@Micha: I’m sure Your proposal will be helpful for others as well. Thank You for Your feedback.
Komentarz od Kubek Bartosz — 31/08/2007 @ 17:48
Hi everyone, i had this problem and solved it simply uncommenting the line “#NameVirtualHost *:80″ on listen.conf file and restarting apache2, thats all.
Komentarz od Ricardo — 03/09/2007 @ 09:54
Had the same problem in Fedora 8. Ricardo’s solution did the trick for me!
Thanks for the help guys!
Komentarz od Koen — 17/11/2007 @ 20:08
Thank you for posting this.Saved me a lot of time!
Just to be clear, I’m on a network of servers, of which the server IP on the local network is 192.168.1.x - Inserting this instead of 127.0.0.1 worked for me.
Komentarz od David Scott — 08/01/2008 @ 03:13
I tried this and didn’t work for me. Instead after some googling I came up with this:
http://redivide.com/2008/03/05/setting-up-a-name-based-virtual-host-vhost/
Komentarz od redivide — 06/03/2008 @ 08:41
Thank you so much for this posting, very useful to me !
Komentarz od tufla — 15/04/2008 @ 03:10
David Scott, THANK YOU.
Komentarz od Karen — 15/04/2008 @ 20:13
You need to add the following line before specifying virtual hosts:
NameVirtualHost *:80
Komentarz od Woland — 18/05/2008 @ 11:16
Ditto - helped me as well, almost a year after you posted it. In my case on Leopard.
Komentarz od Marcus — 22/05/2008 @ 05:51
This also works for me with the wildcards (*) if you enter this line above your vhosts…
NameVirtualHost *:80
[…]
Nick
Komentarz od Nick — 27/05/2008 @ 22:11
[…] _default_ VirtualHost overlap on port 80, the first has precedence | Heavymind you might want to to it this way: NameVirtualHost {{your-ip}}:80 (tags: apache2 virtualhost) […]
Pingback od links for 2008-06-14 — 14/06/2008 @ 06:34
What Woland says is right, it’s not really written out somewhere, but without that line you get the error. You can either make it NameVirtualHost 127.0.0.1:80 or NameVirtualHost *:80 or NameVirtualHost *.*, doesn’t really matter, only changes the scope of what apache2 listens to.
Komentarz od mistermartin75 — 25/06/2008 @ 12:06
This website is Great! I will recommend you to all my friends. I found so much useful things here. Thank you.b
Komentarz od Albert — 25/08/2008 @ 10:17
Thanks friend, it was really helpfull!!!
Komentarz od charasoverride — 24/10/2008 @ 22:11
Thanks, made my night much easier!
Komentarz od tom — 31/10/2008 @ 02:47
pravelno written:)
Komentarz od Henrietta — 06/11/2008 @ 06:05
Thank you very much!! Is fantastic to find people like you!!
Komentarz od maikel — 29/12/2008 @ 22:04
THANK YOU VERY VERY MUCH!!!
Komentarz od matthew — 11/03/2009 @ 22:00
This really helped, thank you very much. You are life saver…
Komentarz od Lion King — 07/05/2009 @ 10:47
It too helped me lot. Thanks to you.
Komentarz od Carbonrock — 10/05/2009 @ 13:21
I owe you a beer!
Komentarz od Antonin Hildebrand — 21/08/2009 @ 22:07
Dude,
You have helped me so much!
Thank you, Thank you, Thank you
Komentarz od Nigel Hughes — 23/09/2009 @ 11:34
NameVirtualHost *:80 was all I think you needed to add to your httpd.conf file
Komentarz od Koku — 19/11/2009 @ 20:33
I had the same problem, suddenly and unexpectedly NameVirtualHost *:80 VirtualHost *:80 stopped working, even giving me the “VirtualHost overlap” error above (I am running Ubuntu Hardy). I have no idea why this happened, I did not perform any upgrade or changes to Apache2, all I did was make a backup of my drive and switch over to it. Anyways, I tried several of the solutions posted here and nothing worked, then finally I discovered this solution which works:
In default VirtualHost:
NameVirtualHost *
VirtualHost *
In all other virtual hosts:
VirtualHost *
Komentarz od Paul — 04/02/2010 @ 18:16
The following works well for me, supports SSL, and allows me to host unlimited subdomains
NameVirtualHost *:80
NameVirtualHost *:443
Komentarz od Caleb Adam Haye — 03/03/2010 @ 05:00
For folks looking to have Apache listen only on 127.0.0.1 (Nginx front-end etc.) and host multiple subdomains in Apache, try the following:
NameVirtualHost 127.0.0.1
Listen 127.0.0.1:80
And in your VirtualHost setup add <VirtualHost 127.0.0.1>
Now when you restart Apache, you will not get any errors on “mixing * ports and non-* ports” or “[warn] _default_ VirtualHost overlap on port 80″
Komentarz od Balaji Dutt — 09/06/2010 @ 10:58