免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3921 | 回复: 6
打印 上一主题 下一主题

跪求:域名混乱问题求解。高手来个。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 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>
ServerName  www.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上)。
各位大侠,是何原?请剖析。

论坛徽章:
0
3 [报告]
发表于 2013-05-30 17:56 |只看该作者
本帖最后由 satrun7 于 2013-05-31 11:45 编辑

  1. <Virtualhost 192.168.0.10:80>
  2.         ServerName  a.com
  3.         ServerAlias www.a.com
  4.         DocumentRoot  /var/www/html
  5.         DirectoryIndex index.html index.php
  6. </Virtualhost>


  7. <Virtualhost 192.168.0.11:80>
  8.         ServerName  b.com
  9.         ServerAlias www.b.com
  10.         DocumentRoot  /var/www/html2
  11.         DirectoryIndex index.html index.php
  12. </Virtualhost>


  13. <Virtualhost 192.168.0.12:80>
  14.         ServerName  c.com
  15.         ServerAlias www.c.com
  16.         DocumentRoot  /var/www/html3
  17.         DirectoryIndex index.html index.php
  18. </Virtualhost>
复制代码
然后在 /etc/hosts ,加入
192.168.0.10 a.com
192.168.0.11 b.com
192.168.0.12 c.com

论坛徽章:
0
4 [报告]
发表于 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中被取消了吧。

论坛徽章:
0
7 [报告]
发表于 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


论坛徽章:
0
2 [报告]
发表于 2013-05-30 17:08 |只看该作者
来个高手。求来。

论坛徽章:
0
5 [报告]
发表于 2013-05-30 18:10 |只看该作者
那就删除掉NameVirtualHost指令.

论坛徽章:
0
6 [报告]
发表于 2013-05-31 09:25 |只看该作者
如果删除NameVirtualHost指令,那就是我现在的配置,故障依旧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP