简体   繁体   English

使用带Nginx和Unicorn的Websockets的Rails?

[英]Rails using Websockets with Nginx and Unicorn?

I am considering implementing chess (which needs websockets) with Rails, and in production deployment using Nginx as a reverse proxy to a bunch of Unicorn processes. 我正在考虑使用Rails实现国际象棋(需要websockets),并在生产部署中使用Nginx作为一堆Unicorn进程的反向代理。

In thinking about how to make that work led me to have the following questions: 在考虑如何完成这项工作时,我得到了以下问题:

As far as I understand websockets are a persistent connection. 据我所知,websockets是一个持久的连接。 Since everything goes through the reverse proxy Nginx how exactly would a Unicorn worker process maintain a websocket connection to a client browser? 因为一切都通过反向代理Nginx,Unicorn工作进程究竟会如何维护到客户端浏览器的websocket连接? Would Nginx maintain state about which Unicorn process each browser websocket is connected to and act as a kind of intermediary? Nginx会维护每个浏览器websocket连接到哪个Unicorn进程的状态并充当一种中介吗? Does keeping a persistent websocket connection in a Unicorn process block the entire worker process? 在Unicorn进程中保持持久的websocket连接会阻止整个工作进程吗?

Is there a recommended way to implementing chess (with websockets) using Rails? 是否有推荐的方法使用Rails实现国际象棋(使用websockets)?

Connecting synchronous processing by Unicorn with asynchronous delivery using nginx would imply some logic on nginx side that seems at least awkward to me. 连接Unicorn的同步处理和使用nginx的异步传递意味着nginx方面的一些逻辑对我来说似乎至少很尴尬。 At most - impossible. 最多 - 不可能。

There is a Railscast about Private Pub gem that makes use of Thin webserver. 有一个关于Private Pub gem的Railscast使用Thin webserver。 It's way more suitable for this task: it's asynchronous, it's able to handle many concurrent requests with event-based IO. 它更适合这项任务:它是异步的,它能够处理许多基于事件的IO的并发请求。 So I suggest you replace Unicorn with Thin or install Thin side-by-side. 所以我建议你用Thin替换Unicorn或者并排安装Thin。

Puma webserver might also be an option, however, I can't give more info about that. Puma网络服务器也可能是一个选项,但是,我无法提供更多信息。

nginx won't do websockets. nginx不会做websockets。 Are you sure you can't do this with AJAX? 你确定你不能用AJAX做到这一点吗? If you really need push capability you could try something built around the Comet approach: http://en.wikipedia.org/wiki/Comet_(programming) 如果你真的需要推送功能,你可以尝试围绕Comet方法构建的东西: http//en.wikipedia.org/wiki/Comet_ (programming)

Faye is a pretty good gem for implementing comet in rails: http://faye.jcoglan.com/ Faye是实现铁轨彗星的一个非常好的宝石: http//faye.jcoglan.com/

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

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