【发布时间】:2014-06-15 08:16:05
【问题描述】:
我有带有 gem websocket-rails 0.7 的 Rails 3.2 应用程序。
在开发机器上,一切正常
在生产环境中,我使用 Nginx/1.6 作为代理服务器,使用 Unicorn 作为 http 服务器。 Thin 用于独立模式(在https://github.com/websocket-rails/websocket-rails/wiki/Standalone-Server-Mode 之后)。
nginx 配置:
location /websocket {
proxy_pass http://localhost:3001/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
在后端,我有以下代码用于向客户发送通知
WebsocketRails[:callback_requests].trigger 'new', call_request
在客户端,我通过以下方式建立了连接:
dispatcher = new WebSocketRails window.location.host + ':3001/websocket'
channel = dispatcher.subscribe 'callback_requests'
但是通知没有到达客户端。
github 上的相关问题 - github.com/websocket-rails/websocket-rails/issues/211
【问题讨论】:
-
你解决过这个问题吗?
-
@jay 我能够通过使用 Thin 作为通用 http 服务器来解决这个问题,而无需独角兽。但是对于 unicorn + thin(for websocket) + nginx 我还没有找到解决方案
-
你在哪个端口上运行 Nginx?您的客户端代码正在调用 3001,但随后您也代理到 3001。 Nginx 和 Thin 不可能在同一台服务器上同时提供 3001。
-
Nginx 在 80 上运行。unicorn 是套接字,在 3001 上很瘦。
标签: ruby-on-rails ruby nginx websocket unicorn