Tomcat服务器无法“外部"运行. [英] Tomcat server not working "externally"

查看:174
本文介绍了Tomcat服务器无法“外部"运行.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了tomcat服务器,它可以在本地主机上运行,​​但是我不能在外部运行它.我需要更改一些设置吗? 我尝试了所有方法,但在其他地方似乎无法正常工作……这很奇怪,因为它在本地主机上运行良好.

I have my tomcat server set up and it works on LOCAL-HOST, however I can't run it externally. Do I have to change some settings? I tried everything but it doesn't seem to work else where... It is weird because it works perfectly fine on local host.

推荐答案

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

So you are running tomcat within a spring boot app, started from the maven spring boot plugin and it listens on localhost but can't be reached using your LAN IP address.

仅需注意-SO上的人们渴望提供帮助,但获取必要的信息也不应该是寻宝.

第一

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

Check which IP address and port tomcat is listening on: the spring boot log will usually tell you the name of the host, eg mymac.local, and the port will be shown, 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),所以很奇怪,这对您不起作用.

And as a rule tomcat starts listening on all IP addresses (0.0.0.0) so it's odd this doesn't work for you.

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

Another way to do this is with netstat. For 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或诸如192.168.0.100之类的真实IP,则您可能会以某种方式受到防火墙或网络的阻止.

If your app is listening on 0.0.0.0 or a real IP like 192.168.0.100 or something then you are likely getting firewalled or blocked on the network somehow.

如果您的应用仅在localhost/127.0.0.1上侦听,则需要告诉tomcat使用真实IP,例如以下问题: 如何配置嵌入式Tomcat集成除了本地主机,还可以使用Spring侦听IP地址请求?

If your app is listening only on localhost/127.0.0.1 then you need to tell tomcat to use the real IP, like this question: How to configure embedded Tomcat integrated with Spring to listen requests to IP address, besides localhost?

第二 与简单的客户端(例如curl/telnet/netcat)进行基本连接.浏览器(尤其是IE)可能会受到Windows组策略等限制,这将阻止许多事情在信息很少或根本没有的情况下工作.

Secondly Do a basic connectivity with a simple client like curl/telnet/netcat. Browsers, especially IE, may be subject to restrictions like Windows Group Policy, that will prevent many things working with little or no information.

因此,在另一台计算机上,看看是否可以远程登录到tomcat端口(假设tomcat在192.168.0.100上运行):

So on a different machine, see if you can telnet to the tomcat port (assuming tomcat is running on 192.168.0.100):

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

如果看到已连接消息,则表明已建立连接,因此,如果浏览器无法正常运行,则说明存在其他问题.

If you see the Connected message then you have connectivity, so if it's not working from the browser then there is something else wrong.

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

If it is refused right away then there is no route / connection between the 2 computers. This usually means your tomcat is not listening on the correct IP address

$ 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

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

If it just hangs on the connecting message then it's probably a firewall.

$ telnet 192.168.0.100 8080
Trying 192.168.0.100...

这篇关于Tomcat服务器无法“外部"运行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆