无法在远程Linux服务器上访问tomcat

时间:2018-07-05 22:38:31

标签: tomcat

我有一个位于192.168.168.1(子网掩码/ 24)的远程Linux服务器,该服务器已安装并运行了tomcat。我知道它正在运行,因为当我SSH到它并执行“ wget localhost:8080”时,我得到:

Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... connected.
HTTP request sent, awaiting response... 200
Length: unspecified [text/html]
Saving to: ‘index.html.1’

    [ <=>                                   ] 11,230      --.-K/s   in 0s

2018-07-05 15:37:21 (184 MB/s) - ‘index.html.1’ saved [11230]

我的本​​地Windows计算机位于同一网络上,其IP地址为192.168.168.2,当我打开浏览器并在网址栏中输入“ 192.168.168.1:8080”时,它告诉我一段时间后连接超时。

我可以从Windows计算机上ping linux服务器,没有问题。

我是否需要针对tomcat / linux服务器进行配置,以便能够从本地计算机调用tomcat?

1 个答案:

答案 0 :(得分:1)

1)服务器端的测试告诉您localhost正在解析ipv4和ipv6回送地址,但可能无法解析为192.168.168.1:
Resolving localhost (localhost)... ::1, 127.0.0.1

2)检查tomcat绑定到的IP地址
netstat -nltss -nlt
如果您看到类似
的条目 tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
这意味着tomcat已绑定到所有可用IP,那么这就是主机或服务器上的防火墙问题。

如何修复

  • 检查防火墙。
  • 在server.xml中检查address属性,如果它显示localhost,请将其更改为0.0.0.0192.168.168.1

    <Connector port="8080" protocol="HTTP/1.1" address="0.0.0.0" connectionTimeout="20000" maxPostSize="2147483647" redirectPort="8443" />

要进行测试,请在服务器端上运行wget http://192.168.168.1.1:8080,然后在浏览器中进行测试。
Tomcat official doc for Connector element