代码之家  ›  专栏  ›  技术社区  ›  tlehman

WebSocket握手不适用于已部署的rails 4.2应用程序

  •  0
  • tlehman  · 技术社区  · 11 年前

    我正在做一个 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

    enter image description here

    1 回复  |  直到 11 年前
        1
  •  1
  •   tlehman    11 年前

    握手失败的原因是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 表示使用WebSocket所需的HTTP 1.1。

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