【问题标题】:WebSocket handshake not working for deployed rails 4.2 appWebSocket 握手不适用于已部署的 rails 4.2 应用程序
【发布时间】:2015-08-31 00:28:46
【问题描述】:

我正在使用Go Game in rails,为了启用实时游戏,我正在使用 websockets。 websocket-rails gem 可以很好地解决这个问题,而且我的一切都在本地工作。

部署到http://goga.me 后,WebSocket 握手失败并显示Websocket connection to 'ws://goga.me/websocket' failed: Error during WebSocket handshake: Unexpected response code: 200

【问题讨论】:

    标签: ruby-on-rails websocket


    【解决方案1】:

    握手失败的原因是 nginx 没有确认 WebSocket 升级:

    将这个添加到 nginx 配置解决了这个问题:

    location /websocket {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    

    proxy_http_version 1.1 选项表示使用 HTTP 1.1,这是 WebSockets 所必需的。

    然后下面两行告诉 nginx 确认升级并完成握手。这在 High Performance Browser Networking

    中已注明

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 2015-11-22
      • 1970-01-01
      • 2022-12-10
      • 1970-01-01
      相关资源
      最近更新 更多