Nginx反向代理重新打包分块响应

我正在运行nginx / 1.1.19:

# nginx -V nginx version: nginx/1.1.19 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-dav-ext-module 

我正在使用它来反向代理服务,可以stream数据作为分块的响应。 后端服务中的每个块都是一个有效的JSON文档,但是当通过nginx代理访问时,块被重新打包成'round'大小,如0x1000,0x2000,0x4000等。这使得块不再有效的JSON blob,每个块将在开始时具有一个文档的结尾,并在结尾处具有另一个文档的开头。

我的location块是这样configuration的:

  location / { proxy_pass http://backend; proxy_read_timeout 600; proxy_buffering off; } 

我以为proxy_buffering off; 部分应该避免我所看到的行为。 有其他的设置我需要改变吗?

您不应该将您的业务数据绑定到块。 块大小可以通过代理来改变,或者由不同的web服务器来改变。 甚至一些基于一些启发式的代理可能会聚合这些块。 你的块parsing器(客户端SDK,如果你有的话)应该能够parsing你的数据,即使每个块都有JSON或者1.5 JSON或者多个JSON的一部分。