【问题标题】:Tornado WebSocket Server without proxy没有代理的 Tornado WebSocket 服务器
【发布时间】:2013-03-09 22:51:58
【问题描述】:

我有一个可以在我的本地机器上正常工作的 tornado websocket 服务器。但是当我将它部署到 Web 服务器并使用 supervisord 运行它时,我无法连接到 javascript websockets。 我试图在防火墙中打开端口,但不起作用。 我还尝试使用带有 nginx(和 tcp 模块)的代理

tcp {
    upstream websockets {
        server abc.de.efg.hij:23581;
        check interval=3000 rise=2 fall=5 timeout=1000;
    }

    server {
        listen abc.de.efg.hij:45645;
        server_name _;

        tcp_nodelay on;
        proxy_pass websockets;
    }
}

但也不起作用。 这里有什么问题?

【问题讨论】:

  • 尝试使用haproxy
  • 您现在可以使用 Nginx 作为 websockets 的反向代理。有关操作方法,请参阅 proxying-websockets-with-nginx

标签: nginx websocket tornado


【解决方案1】:

您需要为 websocket 添加一个额外的“位置”部分,以确保正确传递升级标头:

location /YOUR_SOCKET_ENDPOINT/ {
    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

文档在这里:http://nginx.org/en/docs/http/websocket.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多