Tomcat服务器无法"外部"工作

use*_*209 1 spring tomcat spring-mvc maven server

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

str*_*y05 14

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

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

第一

检查哪些IP地址和端口Tomcat监听上:春天启动日志通常会告诉你的主机,如名mymac.local,端口将被显示,端口: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
Run Code Online (Sandbox Code Playgroud)

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

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

$ netstat -an  | grep 8080
tcp46      0      0  *.8080                 *.*                    LISTEN     
Run Code Online (Sandbox Code Playgroud)

在窗户上

C:\> netstat -an | find "8080"    
  TCP    0.0.0.0:8080            0.0.0.0:0              LISTENING
  TCP    [::]:8080               [::]:0                 LISTENING
Run Code Online (Sandbox Code Playgroud)

如果您的应用程序正在侦听0.0.0.0或真实的IP,如192.168.0.100或其他什么,那么您可能会以某种方式在网络上受到防火墙或阻止.

如果你的应用只在localhost/127.0.0.1上监听,那么你需要告诉tomcat使用真正的IP,比如这个问题: 除了localhost之外,如何配置与Spring集成的嵌入式Tomcat来监听对IP地址的请求?

其次 ,使用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 '^]'.
Run Code Online (Sandbox Code Playgroud)

如果你看到Connected消息然后你有连接,所以如果它不能在浏览器中工作,那么还有其他错误.

如果它立即被拒绝,则两台计算机之间没有路由/连接.这通常意味着您的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
Run Code Online (Sandbox Code Playgroud)

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

$ telnet 192.168.0.100 8080
Trying 192.168.0.100...
Run Code Online (Sandbox Code Playgroud)