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

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

我有一台远程 Linux 服务器,地址为 192.168.168.1(子网掩码 /24),其中安装并运行着 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 位于同一网络上,当我打开浏览器并在 URL 栏中输入“192.168.168.1:8080”时,一段时间后它会告诉我连接超时。

我可以从我的 Windows 机器 ping Linux 服务器,没有任何问题。

我还编辑了我的 iptables 以允许来自端口 8080 的传入连接;这是“sudo iptables -L -v”的结果:

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination 
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp dpt:webcache
    0     0 ACCEPT     udp  --  virbr0 any     anywhere             anywhere             udp dpt:domain
    0     0 ACCEPT     tcp  --  virbr0 any     anywhere             anywhere             tcp dpt:domain
    0     0 ACCEPT     udp  --  virbr0 any     anywhere             anywhere             udp dpt:bootps
    0     0 ACCEPT     tcp  --  virbr0 any     anywhere             anywhere             tcp dpt:bootps
17974   11M ACCEPT     all  --  any    any     anywhere             anywhere             ctstate RELATED,ESTABLISHED
   14   863 ACCEPT     all  --  lo     any     anywhere             anywhere    
 288K   30M INPUT_direct  all  --  any    any     anywhere             anywhere 
 288K   30M INPUT_ZONES_SOURCE  all  --  any    any     anywhere             anywhere
 288K   30M INPUT_ZONES  all  --  any    any     anywhere             anywhere  
    0     0 DROP       all  --  any    any     anywhere             anywhere             ctstate INVALID
 288K   30M REJECT     all  --  any    any     anywhere             anywhere             reject-with icmp-host-prohibited
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere             state NEW tcp dpt:webcache
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere             state NEW tcp dpt:http

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination 
    0     0 ACCEPT     all  --  any    virbr0  anywhere             192.168.122.0/24     ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  virbr0 any     192.168.122.0/24     anywhere    
    0     0 ACCEPT     all  --  virbr0 virbr0  anywhere             anywhere    
    0     0 REJECT     all  --  any    virbr0  anywhere             anywhere             reject-with icmp-port-unreachable
    0     0 REJECT     all  --  virbr0 any     anywhere             anywhere             reject-with icmp-port-unreachable
    0     0 ACCEPT     all  --  any    any     anywhere             anywhere             ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere    
    0     0 FORWARD_direct  all  --  any    any     anywhere             anywhere
    0     0 FORWARD_IN_ZONES_SOURCE  all  --  any    any     anywhere             anywhere
    0     0 FORWARD_IN_ZONES  all  --  any    any     anywhere             anywhere
    0     0 FORWARD_OUT_ZONES_SOURCE  all  --  any    any     anywhere             anywhere
    0     0 FORWARD_OUT_ZONES  all  --  any    any     anywhere             anywhere
    0     0 DROP       all  --  any    any     anywhere             anywhere             ctstate INVALID
    0     0 REJECT     all  --  any    any     anywhere             anywhere             reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 73 packets, 7176 bytes)
 pkts bytes target     prot opt in     out     source               destination 
    0     0 ACCEPT     udp  --  any    virbr0  anywhere             anywhere             udp dpt:bootpc
12493 1460K OUTPUT_direct  all  --  any    any     anywhere             anywhere

Chain FORWARD_IN_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination 
    0     0 FWDI_public  all  --  ens32  any     anywhere             anywhere            [goto]
    0     0 FWDI_public  all  --  +      any     anywhere             anywhere            [goto]

Chain FORWARD_IN_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain FORWARD_OUT_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination 
    0     0 FWDO_public  all  --  any    ens32   anywhere             anywhere            [goto]
    0     0 FWDO_public  all  --  any    +       anywhere             anywhere            [goto]

Chain FORWARD_OUT_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain FORWARD_direct (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain FWDI_public (2 references)
 pkts bytes target     prot opt in     out     source               destination 
    0     0 FWDI_public_log  all  --  any    any     anywhere             anywhere
    0     0 FWDI_public_deny  all  --  any    any     anywhere             anywhere
    0     0 FWDI_public_allow  all  --  any    any     anywhere             anywhere
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere    

Chain FWDI_public_allow (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain FWDI_public_deny (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain FWDI_public_log (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain FWDO_public (2 references)
 pkts bytes target     prot opt in     out     source               destination 
    0     0 FWDO_public_log  all  --  any    any     anywhere             anywhere
    0     0 FWDO_public_deny  all  --  any    any     anywhere             anywhere
    0     0 FWDO_public_allow  all  --  any    any     anywhere             anywhere

Chain FWDO_public_allow (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain FWDO_public_deny (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain FWDO_public_log (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain INPUT_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination 
 288K   30M IN_public  all  --  ens32  any     anywhere             anywhere            [goto]
    9  1863 IN_public  all  --  +      any     anywhere             anywhere            [goto]

Chain INPUT_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain INPUT_direct (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain IN_public (2 references)
 pkts bytes target     prot opt in     out     source               destination 
 288K   30M IN_public_log  all  --  any    any     anywhere             anywhere
 288K   30M IN_public_deny  all  --  any    any     anywhere             anywhere
 288K   30M IN_public_allow  all  --  any    any     anywhere             anywhere
    9   504 ACCEPT     icmp --  any    any     anywhere             anywhere    

Chain IN_public_allow (1 references)
 pkts bytes target     prot opt in     out     source               destination 
    6   312 ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp dpt:ssh ctstate NEW

Chain IN_public_deny (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain IN_public_log (1 references)
 pkts bytes target     prot opt in     out     source               destination 

Chain OUTPUT_direct (1 references)
 pkts bytes target     prot opt in     out     source               destination

为了能够从本地机器调用 tomcat,我需要对 tomcat/linux 服务器进行一些配置吗?

答案1

也许 tomcat 只监听来自某个特定 ip 的连接,最有可能是 localhost。你可以运行netstat -lntu,你会在第 5 列得到类似这样的结果:

        *:22
127.0.0.1:80

第一个表示它正在监听来自任何 IP 的连接,第二个表示它只监听来自本地计算机(服务器本身)的连接。如果 tomcat 只监听本地主机,则必须将文件中的 IP 配置tomcat/conf/server.xml0.0.0.0。如下所示:

<Connector 
  port="8080"
  address="0.0.0.0"
  ...
/>

抱歉,我发布的答案可能不是解决方案。如果可以的话,我会发表评论。

相关内容