当前位置: > Linux服务器 > apache >

apache 多域名共用80端口 虚拟主机

时间:2016-02-02 20:02来源:linux.it.net.cn 作者:IT
提示:

[Wed Jun 18 04:58:38 2008] [warn] _default_ VirtualHost overlap on port 80, the first has precedence



解决: 确保有下面这行

NameVirtualHost *:80



使用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
(责任编辑:IT)
------分隔线----------------------------