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