配置nginx不暂存服务端的响应到缓冲区

nginx做代理的服务器的时候是默认等后端服务器完成响应后再一次把内容返回给用户。这个关键的配置项目是proxy_buffering.
proxy_buffering 默认是on

This directive activate response buffering of the proxied server.
If buffering is activated, then nginx reads the answer from the proxied server as fast as possible, saving it in the buffer as configured by directives proxy_buffer_size andproxy_buffers. If the response does not fit into memory, then parts of it will be written to disk.

If buffering is switched off, then the response is synchronously transferred to client immediately as it is received. nginx does not attempt to read the entire answer from the proxied server, the maximum size of data which nginx can accept from the server is set by directive proxy_buffer_size.

Also note that caching upstream proxy responses won’t work if proxy_buffering is set to off.
For Comet applications based on long-polling it is important to set proxy_buffering to off, otherwise the asynchronous response is buffered and the Comet does not work.

Buffering can be set on a per-request basis by setting the X-Accel-Buffering header in the proxy response.
对于有的应用是有服务端自己推送数据的,需要把proxy_buffering设置为off,不然达不到预想的效果。

此条目发表在nginx分类目录。将固定链接加入收藏夹。

发表回复