用于 Socket.IO 的 Nginx 反向代理以特定大小丢弃消息 [英] Nginx reverse proxy for Socket.IO dropping messages at a certain size

查看:98
本文介绍了用于 Socket.IO 的 Nginx 反向代理以特定大小丢弃消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下配置将 nginx 设置为反向代理.

I have nginx setup as a reverse proxy with the following config.

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include  mime.types;

    default_type  application/octet-stream;
    keepalive_timeout  65;

    map $http_upgrade $connection_upgrade {
        default  upgrade;
        ''  close;
    }

    server {
        listen  8080;

        server_name  localhost;

        add_header  X-Cache-Status  $upstream_cache_status;

        location /node/ {
            proxy_http_version  1.1;
            proxy_pass   http://127.0.0.1:8000/;
            proxy_redirect  off;
            proxy_set_header  Connection  $connection_upgrade;
            proxy_set_header  Upgrade  $http_upgrade;
        }
    }
}

我正在使用以下代码连接到它.

I'm connecting to it with the following code.

socket = io.connect('http://localhost:8080', {
    'resource': 'node/socket.io'
});

一旦连接,一切正常,除了 Node.js 永远不会收到超过 15kb 的消息.Nginx 不会在访问或错误日志中记录任何内容.

Once connected, everything works normally, except that messages above around 15kb are never received by Node. Nginx doesn't log anything to the access or error logs.

我很确定这是 nginx 配置问题,但我没有发现任何影响此行为的设置.我试过 client_body_buffer_size sizeproxy_buffersproxy_buffer_sizetcp_nodelaylarge_client_header_buffers.

I'm pretty sure it's an nginx configuration issue, but I haven't found any settings that affect this behavior. I've tried client_body_buffer_size size, proxy_buffers, proxy_buffer_size, tcp_nodelay, and large_client_header_buffers.

如何让 nginx 停止丢弃这些消息?

How can I get nginx to stop dropping these messages?

推荐答案

我想问题确实与代理缓冲区有关,只是我没有将它们设置得足够高.以下内容现在适用于 5mb 左右的消息.

I guess the problem did have to do with the proxy buffers, I just hadn't set them high enough. The following is working now for messages around 5mb.

proxy_buffers 8 2m;
proxy_buffer_size 10m;
proxy_busy_buffers_size 10m;

这篇关于用于 Socket.IO 的 Nginx 反向代理以特定大小丢弃消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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