您的位置:首页 > 运维架构 > Tomcat

tomcat 127.0.0.1 不能访问,但是用咯calhost可以访问

2013-10-14 13:42 447 查看
今天玩tomcat的时候,忽然发现了一个非常见的问题,写个日志记录下来。
tomcat版本: 5.5.33

服务端口: 8085

运行tomcat_home\bin\startup.bat 文件来启动tomcat.

启动正常,开始登陆tomcat。

在浏览器的地址栏输入:
http://127.0.0.1:8085http://192.168.6.84:8085 , 浏览器返回“无法打开该页面”。

输入 http://localhost:8085http://james-notebook:8085 却可以打开tomcat的页面。

难道 127.0.0.1 和 localhost不同? 难道我的网卡有问题?

-------------------------------------------------------------------------------------------------

网上找了一个相似的问题:"127.0.0.1可以访问tomcat,但localhost缺无法访问。"

这种问题的解决方案是:

进入C:\WINDOWS\system32\drivers\etc目录下,

查看hosts 文件中是否含有"127.0.0.1 localhost”, (注意:127.0.0.1前面不要有任何东西,特别是#号).

-------------------------------------------------------------------------------------------------

上面那种问题只要确保hosts文件中的配置正确就可以解决。

但是我这次发现的问题和上面的刚好相反:localhost可以访问tomcat,127.0.0.1访问不到!

127.0.0.1是网络中的回环地址,localhost只是本地主机地址。一般情况下两者是相同的。

localhost可以访问tomcat,127.0.0.1不能访问,难带是127.0.0.1出问题了?

我在命令行中分别ping 127.0.0.1 和 localhost 显示效果如下:

C:\Documents and Settings\Administrator>ping 127.0.0.1

Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=64

......

C:\Documents and Settings\Administrator>ping localhost

Pinging PC-201005210950 [::1] with 32 bytes of data:

Reply from ::1: time<1ms

......

发现了个问题:

在ping localhost时正常应该返回的是127.0.0.1,结果返回的却是 " ::1" 。

" ::1 " 这种写法是IPv6中的ip地址格式,相当于IPv4中的127.0.0.1 。

刚才我用http://127.0.0.1:8085 访问不到tomcat,然后我用 http://[::1]:8085 发现可以成功地访问到tomcat了。 至此源码天空,我怀疑导致不能用ip访问tomcat的问题是因为IPv6原因。

我打开网卡属性,发现其中安装了"Microsoft TCP/IP 版本 6"。
卸载掉IPv6,就可以使用IP访问tomcat了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐