大网数据广告活动
服务器运维问答

Nginx: How To Completely Disable Request Body Buffering

· 52CE 我爱测

I'm trying to set up Madsonic on my Ubuntu box and have Nginx run in front of it. Problem is, I keep getting this warning when I try to upload stuff through the web interface: 31115#0: *14 a client request body is buffered to a t…

问题原文

原帖链接 · rad · CC BY-SA 3.0

I'm trying to set up Madsonic on my Ubuntu box and have Nginx run in front of it. Problem is, I keep getting this warning when I try to upload stuff through the web interface:

31115#0: *14 a client request body is buffered to a temporary file

This also explains why progress bars on the upload window doesn't work. Here's my relevant Nginx configuration:

    # proxy the madsonic server here
    location / {
            proxy_pass                      https://madsonic-server/;
            proxy_redirect                  off;
            proxy_buffering                 off;
            proxy_request_buffering         off;
            allow                           all;
            proxy_http_version              1.1;

            proxy_set_header                Host $http_host;
            proxy_set_header                X-Real-IP $remote_addr;
            proxy_set_header                X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header                X-Forwarded-Host $server_name;
            proxy_set_header                X-Forwarded-Proto $scheme;

            client_body_buffer_size         0;
            client_max_body_size            0;
            proxy_max_temp_file_size        0;
            proxy_read_timeout              18000;
            proxy_send_timeout              18000;

            gzip                            off;
    }

I'm using Nginx 1.9.12 at the moment.

What I'd like to achieve is to make Nginx not use request body buffers at all and just pass the request body directly to Madsonic, regardless of size. Is this even possible? If it is, what would be the correct configuration?

Other questions seem to get answered with ways to set the buffer sizes. I don't want any buffers. I want to directly pass the request body to Madsonic.

社区高分解答

原帖链接 · Halfgaar · CC BY-SA 3.0

I had the same issue setting up an Nginx proxy for a Docker registry. I ended up doing:

client_max_body_size 0;
proxy_http_version 1.1;
proxy_request_buffering off;

client_max_body_size still had to be 0 to prevent the error, but watch -n 1 du -hs . clearly showed a difference. Buffering made the data appear after the request, no buffering made it appear during the request.

proxy_http_version 1.1 is necessary because of chunked encoding. Quote from the Nginx docs:

When HTTP/1.1 chunked transfer encoding is used to send the original request body, the request body will be buffered regardless of the directive value unless HTTP/1.1 is enabled for proxying.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。