Websocket-rails在Nginx和Unicorn的生产环境中不起作用 [英] Websocket-rails doesn't work on production evironment with Nginx and Unicorn

查看:86
本文介绍了Websocket-rails在Nginx和Unicorn的生产环境中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有gem websocket-rails 0.7的Rails 3.2应用程序.

I have Rails 3.2 application with gem websocket-rails 0.7.

在开发机上,一切正常

在生产环境中,我使用Nginx/1.6作为代理服务器,使用Unicorn作为http服务器. Thin用于独立模式(以下 https://github.com /websocket-rails/websocket-rails/wiki/独立服务器模式).

On production enviroment, I use Nginx/1.6 as proxy server and Unicorn as http server. Thin is used on standalone mode (following 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";
}

在后端,我有以下代码用于向客户端发送通知

On backend side, I have the following code for send notification to clients

WebsocketRails[:callback_requests].trigger 'new', call_request

在客户端,我使用以下方法建立了连接:

On client side, I got a connection using:

dispatcher = new WebSocketRails window.location.host + ':3001/websocket'
channel    = dispatcher.subscribe 'callback_requests'

但是通知不会到达客户端.

But notification doesn't come to the client.

github上的相关问题-github.com/websocket-rails/websocket-rails/issues/211

Related issue on github - github.com/websocket-rails/websocket-rails/issues/211

推荐答案

您的nginx配置将/websocket/以下的请求与结尾的/进行匹配.这是/websocket/blah的目录组件.

Your nginx config is matching requests below /websocket/ with the trailing /. That is the directory component of /websocket/blah.

如果您查看nginx访问日志文件,则会发现您对/websocket的请求正被301重定向到/websocket/.

If you look in your nginx access log file you'll find your requests to /websocket are being 301 redirected to /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";
}

这篇关于Websocket-rails在Nginx和Unicorn的生产环境中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆