Nginx: How To Completely Disable Request Body Buffering

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.


Solution 1:

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.