Websocket-rails 不适用于 Nginx 和 Unicorn 的生产环境

2024-04-21

我有 Rails 3.2 应用程序和 gem websocket-rails 0.7。

在开发机器上,一切正常

在生产环境中,我使用 Nginx/1.6 作为代理服务器,使用 Unicorn 作为 http 服务器。 Thin 用于独立模式(如下https://github.com/websocket-rails/websocket-rails/wiki/Standalone-Server-Mode 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


Your nginx配置与下面的请求匹配/websocket/与尾随/。这是目录组件/websocket/blah.

如果你看看你的nginx访问日志文件你会发现你的请求/websocket正在被 301 重定向到/websocket/.

删除尾随/

location /websocket {
   proxy_pass http://localhost:3001/websocket;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Websocket-rails 不适用于 Nginx 和 Unicorn 的生产环境 的相关文章

随机推荐