哪一天 哪一天 我有吃有穿有住有钱 不再流浪 流浪
« »
May 15, 2008程序设计

82 views

_default_ VirtualHost overlap on port 80, the first has precedence

使用Apache配置虚拟主机出现_default_ VirtualHost overlap on port 80, the first has precedence错误的解决方案:

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

随机日志

日志信息 »

该日志于2008-05-15 14:18由 admin 发表在程序设计分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下引用到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

主机推荐 »

赞助商链接 »

没有评论

发表评论 »

返回顶部