简体   繁体   English

尝试使用Tornado Server打开连接时WebSockets客户端连接超时

[英]WebSockets Client Connections Time Out When Trying to Open a Connection with Tornado Server

I have a Tornado server with a WebSocketHandler, and when I connect to the handler on localhost everything works correctly. 我有一个带有WebSocketHandler的Tornado服务器,当我连接到localhost上的处理程序时,一切正常。 However, the server is being moved to a new environment and now must run on wss instead of ws protocol. 但是,服务器正在移动到新环境,现在必须运行wss而不是ws协议。 Since moving to the new environment, all client connections to my WebSocketHandler time out without ever opening. 自从迁移到新环境后,与WebSocketHandler的所有客户端连接都会超时而不会打开。 telnet connects just fine, however. 然而, telnet接通很好。 The issue occurs in all major browsers, afaik. 这个问题出现在所有主要的浏览器中,afaik。

The firewall has an exception for the port my server is running on, and I've enabled TLS in the Tornado server by sending in my .cer and .key files, but to no avail. 防火墙对我的服务器运行的端口有一个例外,我通过发送我的.cer.key文件在Tornado服务器中启用了TLS,但无济于事。 I also tried following the advice here regarding ProxyPass in an Apache server running on the same environment, and connections are still timing out. 我也尝试按照这里关于在同一环境中运行的Apache服务器中的ProxyPass的建议,并且连接仍然超时。

Environment: CentOS Linux release 7.2.1511 环境:CentOS Linux版本7.2.1511

Relevant Tornado Code: 相关的龙卷风代码:

import tornado.websocket
import tornado.ioloop
import tornado.auth
import tornado.escape
import tornado.concurrent

class WSHandler(tornado.websocket.WebSocketHandler)
    def check_origin(self, origin):
        return True

    def open(self, arg1, arg2):
        self.stream.set_nodelay(True)
        self.arg2 = arg2
        self.write_message("Opened the connection")

class WSApp(tornado.web.Application):
    def __init__(self, arg1=None, arg2=None, handlers=None,
                 default_host='', transforms=None, **settings):
        print("Starting WSApp application")
    super(WSApp, self).__init__(handlers=handlers,
                                       default_host=default_host,
                                       transforms=transforms,
                                       **settings)

if __name__ == "__main__":
    settings = {
        "cookie_secret": b'om nom nom' # /s,
        "ssl_options": {
            "certfile": "path/to/certfile.cer",
            "keyfile": "path/to/keyfile.key"
    }

    application = AMQPWSTunnel(handlers=[
                                (r"/(resource)/(.+)", AMQPWSHandler)
                            ],
                            debug=True,
                            **settings)

    application.listen(8930)

    try:
        tornado.ioloop.IOLoop.current().start()
    except KeyboardInterrupt:
        application.shutdown()

ProxyPass Settings ProxyPass设置

ProxyPass /resource/<resource_name> wss://127.0.0.1:8930/resource/<resource_name>
ProxyPassReverse /resource/<resource_name> wss://127.0.0.1:8930/resource/<resource_name>

WebSocket Connection WebSocket连接

var ws = new Websocket("wss://my-domain:8930/resource/<resource_id>");

Any help would be appreciated! 任何帮助,将不胜感激!

The issue was with ProxyPass settings and the post used in my wss url. 问题在于ProxyPass设置和我的wss网址中使用的帖子。

Tornado Update: 龙卷风更新:

The ssl cert and key files were removed from Tornado configuration. ssl证书和密钥文件已从Tornado配置中删除。

ProxyPass Update: ProxyPass更新:

ProxyPass /resource/<resource_name> ws://127.0.0.1:8930/resource/<resource_name>
ProxyPassReverse /resource/<resource_name> ws://127.0.0.1:8930/resource/<resource_name>

The second argument must be a non-ssl protocol (changed from wss:// to ws:// ), though by keeping the cert in place I probably could have used wss . 第二个参数必须是非ssl协议(从wss://更改为ws:// ),但是通过保留证书,我可能已经使用了wss This is a non-issue, though, because Apache catches incoming WebSocket requests to my server. 但这不是问题,因为Apache会将传入的WebSocket请求捕获到我的服务器。

Client Update: 客户端更新:

The client must send requests to Apache, which then tunnels them to the Tornado server. 客户端必须向Apache发送请求,然后将其隧道传送到Tornado服务器。 So just remove the port from the url (or add Apache's port number) 所以只需从url中删除端口(或添加Apache的端口号)

var ws = new Websocket("wss://my-domain/resource/<resource_id>");

Those three changes did the trick! 这三个变化成功了! Hopefully this is helpful to anyone else stuck on the same issue. 希望这对任何困扰同一问题的人都有帮助。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM