我有带有 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
最佳答案
您的 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";
}
关于ruby-on-rails - Websocket-rails 不适用于 Nginx 和 Unicorn 的生产环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23363874/