happy97550 发表于 2013-05-30 17:05

跪求:域名混乱问题求解。高手来个。

系统环境:

Cenos6.4+Apache2.4.2+PHP5.3.3
本台服务器有多个IP地址。比如:
192.168.0.10
192.168.0.11
192.168.0.12
有多个域名解析到该台机器上。但解析的IP是不同的。如a.com解析到192.168.0.10,b.com解析到192.168.0.11等等。
现httpd.conf中Listen绑定的是80端口,ServerName绑定的是www.a.com
虚拟主机配置如下:
<virtualhost 192.168.0.10:80>
ServerNamewww.a.com
DocumentRoot/var/www/html
DirectoryIndex index.html index.php
</virtualhost>
问题描述如下:
现今,在浏览器访问http://www.a.com,该页面中的链接出现域名混乱。在程序中有如下代码片段:
<a href="<?php echo $_SERVER['HTTP_HOST'];?>/test/">test</a>
结果有些能正确解析为www.a.com/test/,有些则解析为www.b.com/test/,www.c.com/test/,www.d.com/test/(以上域名均解析到本机的IP上)。
各位大侠,是何原?请剖析。

satrun7 发表于 2013-05-30 17:56

本帖最后由 satrun7 于 2013-05-31 11:45 编辑


<Virtualhost 192.168.0.10:80>
        ServerNamea.com
        ServerAlias www.a.com
        DocumentRoot/var/www/html
        DirectoryIndex index.html index.php
</Virtualhost>


<Virtualhost 192.168.0.11:80>
        ServerNameb.com
        ServerAlias www.b.com
        DocumentRoot/var/www/html2
        DirectoryIndex index.html index.php
</Virtualhost>


<Virtualhost 192.168.0.12:80>
        ServerNamec.com
        ServerAlias www.c.com
        DocumentRoot/var/www/html3
        DirectoryIndex index.html index.php
</Virtualhost>然后在 /etc/hosts ,加入
192.168.0.10 a.com
192.168.0.11 b.com
192.168.0.12 c.com

happy97550 发表于 2013-05-30 18:03

谢谢楼上的。我试过后,无效。提示:
Starting httpd: AH00548: NameVirtualHost has no effect and will be removed in the next release /usr/local/apache/conf/extra/httpd-vhosts.conf:1
应该是NameVirtualHost 这个配置指令已经在这个版本(2.4.2)的apache中被取消了吧。

satrun7 发表于 2013-05-31 13:04

CentOS 6.3/X64 + Apache/2.4.4 + Php/5.4.15 , 上面的apache的基于IP虚拟配置 , PHP 的 $_SERVER['HTTP_HOST'] 获取域名正确, 完全没有问题。

网卡配置 :
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:fa:8b:a4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.6.129/24 brd 192.168.6.255 scope global eth0
    inet 192.168.6.130/24 brd 192.168.6.255 scope global secondary eth0:1
    inet 192.168.6.131/24 brd 192.168.6.255 scope global secondary eth0:2
    inet6 fe80::20c:29ff:fefa:8ba4/64 scope link


happy97550 发表于 2013-05-30 17:08

来个高手。求来。:mrgreen:

satrun7 发表于 2013-05-30 18:10

那就删除掉NameVirtualHost指令.

happy97550 发表于 2013-05-31 09:25

如果删除NameVirtualHost指令,那就是我现在的配置,故障依旧。
页: [1]
查看完整版本: 跪求:域名混乱问题求解。高手来个。