繁体   English   中英

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

[英]Websocket-rails doesn't work on production evironment with Nginx and Unicorn

我有使用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的请求被重定向到/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";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM