用nginx作为NodeJS + socket.io的代理:一切正常,除了大消息 [英] nginx as a proxy for NodeJS+socket.io: everything is OK except for big messages

查看:352
本文介绍了用nginx作为NodeJS + socket.io的代理:一切正常,除了大消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nginx网站上所述,我已将这些设置用于我的nginx将websocket代理到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()相互发送消息;直到我发送了一条相当大的短信(HTML为26 kB).

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屋!

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