25

It looks like nginx 0.8.35 may support chunked transfer encoding:

Changes with nginx 0.8.35 01 Apr 2010

*) Change: now the charset filter runs before the SSI filter. *) Feature: the "chunked_transfer_encoding" directive. 

This is great, because I'm trying to get push git changes through an nginx reverse proxy to a git-http-backend process. Git HTTP takes advantage of chunked transfer encoding for client-side efficiency reasons.

However, I can't get it to work. I'm using nginx 0.8.44 on Debian Lenny with the following configure invocation:

./configure \ --sbin-path=/usr/sbin \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --user=www-data \ --group=www-data \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --with-http_ssl_module \ --with-http_gzip_static_module \ --with-http_realip_module 

And the following conf file:

server { server_name example.com; location / { proxy_pass http://192.168.0.10; include /etc/nginx/proxy.conf; chunked_transfer_encoding on; } } 

And my proxy.conf looks like this:

proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 100M; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; 

(Originally I posted this question to Stack Overflow but was advised it's more appropriate to Server Fault)

3
  • 1
    You cannot have buffers as well as chunked encoding. Buffers wait to send data, chunked should send it immediately. Commented Jul 11, 2010 at 16:59
  • Apparently Nginx supports Chunked since version 1.3.9 (27/11/2012). However, I still get "411 Length Required" error messages when a smartphone sends chunked POST requests to my Nginx server. Any advice? Commented May 12, 2013 at 9:05
  • Where you able to adjust the chunk size somehow or know which parameter does this? Commented Mar 7, 2021 at 8:29

4 Answers 4

34

This is an old question, I know, but it came up in a search for the problem (which I've spent the afternoon trying to solve). Martin F's comment gave me enough of a clue to get it working!

The trick is to set proxy_buffering off; in your location block. Assuming that your upstream server is sending back chunked responses, this will cause nginx to send the individual chunks back to the client - even gzipping them on the fly if you have gzip output compression turned on.

Note that turning off buffering may have other disadvantages, so don't go blindly turning off buffering without understanding why.

1
  • 1
    It finally solved my problem with proxying HTTP 1.1 web admin which I tackled for days. Damn. Thank you. Commented May 11, 2020 at 8:09
9

I suggest editing your question to clarify. There is a big difference between chunked requests and chunked responses. John Dalton's answer addresses the latter. Git does both.

Nginx does not currently support chunked POST requests and this posting shows up high in search results on the topic. Chunked POST requests are used when you do not know the amount of data being uploaded in advance and is frequently used by mobile phones.

The only working solution I found is this:

http://wiki.nginx.org/HttpChunkinModule

Unfortunately it requires recompiling nginx as nginx doesn't support loadable modules.

2
  • I agree: I'm finding that HttpChunkinModule is the only theoretical workaround... but it's not open to me in my situation. Does anyone know if anything else can be done? (Any changes since 30 Jan 2011?) Commented Dec 16, 2011 at 0:26
  • 1
    No changes that I know. I just did an nginx recompilation the other day in order to enable this. Commented Dec 18, 2011 at 6:12
7

On my case... i try a lot of things and finally only need add to configuration

proxy_http_version 1.1; 

And it works...

4
  • I had to add proxy_set_header Connection "";... original answer from -> forum.nginx.org/read.php?2,247883,247883#msg-247883 Commented Apr 18, 2017 at 22:24
  • This worked for me as well. But I really don't understand why. Commented Oct 23, 2019 at 13:56
  • 1
    Update to my last comment.... this worked because my upstream server was using Chunked Transfer Encoding, which was introduced in HTTP 1.1 (en.wikipedia.org/wiki/Chunked_transfer_encoding). The default http protocol version for nginx proxying is 1.0. Commented Oct 23, 2019 at 15:13
  • @ChristianUlbrich: You should not set such a header from nginx. It sounds like your upstream app is also doing upstream requests but doesn't cleanup of the response headers (like Connection). You could check that by adding a debug log in the location or by putting something like mitmproxy in between to "see" the headers. Not filtering response headers from upstream systems may cause serious security issues. Commented Jul 10, 2024 at 15:35
1

Other answers used to be valid, but this is an old question.

It seems like Chunked Transfers are supported per nginx 1.3.9[1], which was released mid 2013 I think.

[1] http://wiki.nginx.org/HttpChunkinModule

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.