简体   繁体   English

Windows Server 2012,Apache Tomcat,Spring MVC:外部IP的Websocket连接被阻止

[英]Windows Server 2012, Apache Tomcat, Spring MVC: Websocket connection blocked for external IP

We've deployed our Spring MVC web application on Windows Server 2012 . 我们已经在Windows Server 2012上部署了Spring MVC Web应用程序。 Our web-app uses Spring Websockets for updates with stomp.js and sock.js . 我们的网络应用使用Spring Websockets通过stomp.jssock.js进行更新。

Our websocket configuration: 我们的websocket配置:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic");
        config.setApplicationDestinationPrefixes("/calcApp");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/add").setAllowedOrigins("*").withSockJS();
    }

}

Websocket works on localhost and logs are following: Websocket在本地主机上工作 ,日志如下:

Opening Web Socket...
Web Socket Opened...
>>> CONNECT
accept-version:1.1,1.0
heart-beat:10000,10000

<<< CONNECTED
version:1.1
heart-beat:0,0
user-name:admin

connected to server undefined

>>> SUBSCRIBE
id:sub-0
destination:/topic/resident

...

Strangely, it doesn't work when I enter external ip , on same machine and browser : 奇怪的是,当我在同一台机器和浏览器上输入external ip时,它不起作用:

Opening Web Socket...
WebSocket connection to 'ws://192.168.5.50:8080/autopark/add/629/i148hb1c/websocket' failed: WebSocket is closed before the connection is established.
Whoops! Lost connection to undefined

We thought that for external access , there is some firewall and totally disabled it: 我们认为,对于外部访问 ,有一些防火墙并完全禁用了它:

在此处输入图片说明

But it didn't solve our problem. 但这并不能解决我们的问题。


How can we solve this issue? 我们如何解决这个问题?

I'm not really sure and not a spring expert. 我不太确定,不是春季专家。

but it seems you need to call the server by a domain name over its ip addr which is logical. 但是似乎您需要通过其IP地址上的域名来调用服务器,这是合乎逻辑的。

Since an ip would be used for more than one domain, so it seems the context need to know which context should be called(even if one) in spring context. 由于一个ip将用于多个域,因此似乎上下文需要知道应该在spring上下文中调用哪个上下文(即使是一个)。

in other word, calling the context by ip would confuse the spring context to select/invoke which context/domain, so it refuses the connection. 换句话说,通过ip调用上下文会混淆spring上下文来选择/调用哪个上下文/域,因此它拒绝连接。

have atry, binf the 192.168.5.50 to a domain name, then try to call the path using the domain(not ip). 尝试将192.168.5.50绑定到一个域名,然后尝试使用该域(而非ip)调用路径。 Hope it works this way. 希望它能这样工作。

The first step in debugging this would be verifying that your application server is actually listening on the external interface. 调试的第一步将是验证您的应用服务器实际上是在外部接口上进行侦听。

You can verify what IP your container is bound to by looking for 8080 entries in the output of netstat. 您可以通过在netstat的输出中查找8080条目来验证容器绑定的IP。

The next step should be verifying an external computer can "see" the port on the external IP. 下一步应该是验证外部计算机可以“看到”外部IP上的端口。 There are various ways to do this, but using the telnet command will suffice. 有多种方法可以执行此操作,但是使用telnet命令就足够了。

  • telnet 192.168.5.50 8080
    • If this does not work, then we know there is something blocking communication between the two applications 如果这不起作用,那么我们知道这两个应用程序之间存在阻止通信的问题

If we get to this point, then there is likely an issue with the configuration of the application itself. 如果到此为止,则应用程序本身的配置可能存在问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring MVC-服务器启动错误-Apache Tomcat - spring mvc - error in server start - apache tomcat 外部Apache tomcat服务器 - External Apache tomcat Server 当Apache HTTPD在Tomcat前面时,WebSocket连接中断 - WebSocket connection interrupted when Apache HTTPD in front of Tomcat Apache Httpd和Eclipse Tomcat之间的连接(Windows 7) - Connection between Apache Httpd and Eclipse Tomcat (Windows 7) java-Tomcat数据库连接池未在websocket服务器端点中提供连接 - java - Tomcat database connection pool not giving connection in websocket server endpoint 无法使用apache tomcat使用外部IP连接到我的网站 - Cannot connect to my website using external IP using apache tomcat Spring Boot MVC应用程序在部署到外部Tomcat / tc Server实例时返回HTTP 404 - Spring Boot MVC Application returns HTTP 404 when deployed to an external Tomcat/tc Server instance 如何在Apache Tomcat 6服务器中修复Java Spring MVC Web应用程序的运行时间? - How to fix java spring mvc web application run time in Apache Tomcat 6 server? 从Spring MVC中的Apache tomcat服务器目录以html页面流式传输视频 - stream a video in html page from apache tomcat server directory in spring mvc org.apache.tomcat.websocket.server.WsFilter.doFilter - org.apache.tomcat.websocket.server.WsFilter.doFilter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM