在 nginx 后面部署 deepstream.io

Deploying deepstream.io behind nginx

我们在 nginx 层进行了 kerberos 身份验证,并希望作为反向代理连接到 deepstream.io 个实例。从我对文档的阅读来看,将网络服务器放在 deepstream.io 实例前面似乎会影响性能。此外,还有谁负责负载均衡的问题——通常是在 nginx 层,但 deepstream.io 似乎具有要求其他实例处理负载的内置功能(通过 messaging

让 deepstream.io 实例在 Web 服务器上正常运行的最佳方法是什么?在 Node.

中重新实现 kerberos 身份验证并非易事

在 Nginx、HAProxy 等之后部署和负载平衡 deepstream 是可能的(也是一个好主意)。不过有一些事情需要注意:

engine.io、websockets 和粘性会话

Deepstream 使用 engine.io (the transport-layer behind socket.io) 连接到浏览器。

engine.io 使用多种不同的传输机制,最著名的是长轮询(在需要发送数据之前保持 http 请求打开)和 WebSockets。

对于长轮询,来自同一个客户端的所有请求都被路由到同一个深度流服务器是至关重要的,因此请确保在您的 nginx 上游组中启用 sticky/persistent 会话(只需添加 ip_hash directive). For websocket it is important that the http update headers are forwarded.

在您的 deepstream 节点之间同步数据/消息

确保您的深层节点通过缓存和消息总线相互连接。您可以选择缓存和消息系统,但最简单的是只使用 Redis for both. Have a look at the section on "What’s the simplest production-ready setup?" at the bottom of https://deepstream.io/tutorials/connectors-and-deployment.html.

来自其他客户端(例如 NodeJS)的 TCP 连接 engine.io主要用于浏览器客户端,后端进程可以通过TCP直接连接。使用 NginX 可以完全实现负载均衡 TCP 连接,但需要 extra stream group in your configuration.