nginx作为NodeJS+socket.io的代理:除了大消息,一切正常 [英] nginx as a proxy for NodeJS+socket.io: everything is OK except for big messages
问题描述
如 nginx 网站 所述,我已将这些设置用于我的 nginx将 websockets 代理到 NodeJS 服务器:
As explained on nginx's website I've used these settings for my nginx to proxy websockets to a NodeJS server:
location /socket.io/ {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
一切正常,socket.emit()/socket.on() 相互发送消息;直到我发送了一条相当大的短信(26 kB 的 html).
Everything works fine and socket.emit() / socket.on() send messages to each other; until I send a rather big text message (26 kB of html).
- NodeJS 没有收到这条大消息(所以我猜问题出在 nginx 方面)
- nginx 日志没有错误
- 一旦客户端发送了这条大消息,NodeJS 将停止从该客户端接收 socket.io 的心跳.
我做错了什么?是否有我不知道的 nginx 设置?
What am I doing wrong? Is there a nginx setting that I am not aware of?
推荐答案
找到的解决方案"是使用haproxy 在 nginx 和 NodeJS 之间拆分 tcp 流.
The "solution" found is to use haproxy to split the tcp stream between nginx and NodeJS.
它不是最优的,因为它在我们的堆栈中添加了另一个程序,但它完成了工作.
It is not optimal because it adds yet-another-program in our stack, but it does the job.
在我看来,nginx websocket 支持还远未达到生产就绪状态.
It seems to me that nginx websocket support is still far from being production-ready.
这篇关于nginx作为NodeJS+socket.io的代理:除了大消息,一切正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!