Tomcat服务器无法“外部”工作

时间:2015-04-27 00:21:41

标签: spring maven spring-mvc tomcat server

我设置了tomcat服务器,它可以在LOCAL-HOST上运行,但我不能在外部运行它。我必须更改一些设置吗? 我尝试了所有的东西,但它似乎没有工作在其他地方......这很奇怪,因为它在本地主机上运行得非常好。

1 个答案:

答案 0 :(得分:14)

所以你在一个Spring启动应用程序中运行tomcat,从maven spring启动插件启动,它在localhost上侦听,但无法使用你的LAN IP地址访问。

只是一个注意事项 - SO上的人都热衷于帮助,但它不应该是寻求获取必要信息的宝藏。

<强>第一

检查tomcat正在侦听的IP地址和端口:spring boot log通常会告诉您主机的名称,例如 mymac.local ,并显示端口, port(s):8080(http),:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.3.RELEASE)


2015-04-29 09:14:33.269  INFO 7031 --- [main] hello.Application  Starting Application v0.1.0 on mymac.local with PID 7031 (/Users/foo/Development/java/springframework/gs-spring-boot/complete/target/gs-spring-boot-0.1.0.jar started by foo in /Users/foo/Development/java/springframework/gs-spring-boot/complete)
2015-04-29 09:14:35.072  INFO 7031 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2015-04-29 09:14:35.506  INFO 7031 --- [main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2015-04-29 09:14:35.507  INFO 7031 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.20

通常,tomcat会开始监听所有IP地址(0.0.0.0),所以它很奇怪,这对你不起作用。

另一种方法是使用netstat。对于Max / Linux:

$ netstat -an  | grep 8080
tcp46      0      0  *.8080                 *.*                    LISTEN     

在Windows上

C:\> netstat -an | find "8080"    
  TCP    0.0.0.0:8080            0.0.0.0:0              LISTENING
  TCP    [::]:8080               [::]:0                 LISTENING

如果您的应用正在收听0.0.0.0或真实IP(如192.168.0.100)或其他内容,那么您可能会以某种方式在网络上受到防火墙或阻止。

如果你的应用只在localhost / 127.0.0.1上监听,那么你需要告诉tomcat使用真正的IP,就像这个问题: How to configure embedded Tomcat integrated with Spring to listen requests to IP address, besides localhost?

<强>其次 与curl / telnet / netcat等简单客户端建立基本连接。浏览器,尤其是IE浏览器,可能会受到Windows组策略等限制,这可能会阻止许多事情处理很少或根本没有信息。

所以在另一台机器上,看看你是否可以telnet到tomcat端口(假设tomcat在192.168.0.100上运行):

$ telnet 192.168.0.100 8080
Trying 192.168.0.100...
Connected to localhost.
Escape character is '^]'.

如果您看到已连接消息,那么您就有了连接,所以如果它无法通过浏览器运行,那么还有其他问题。

如果立即拒绝,则两台计算机之间没有路由/连接。这通常意味着您的tomcat没有侦听正确的IP地址

$ telnet 192.168.0.100 8080
Trying  192.168.0.100...
telnet: connect to address  192.168.0.100: Connection refused
telnet: Unable to connect to remote host

如果它只是挂在连接消息上,那么它可能是防火墙。

$ telnet 192.168.0.100 8080
Trying 192.168.0.100...