Nginx – Enabling Chunked Transfer Encoding

chunkedgitnginx

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)

Best Answer

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.