售前咨询
技术支持
渠道合作

nginx proxy buffer 解释

遇到一例 nginx buffer 设置太小,如果 URL 比较长导致 504 错误的故障。可以看看这篇网站502与504错误分析。

下面总结下 nginx buffer 设置:

首先,这些参数都是针对每一个http request ,不是全局的。

proxy_buffering

proxy_buffering 开启的时候,proxy_buffers 和proxy_busy_buffers_size 才会起作用,无论proxy_buffering 是否开启,proxy_buffer_size 都起作用。

proxy_buffer_size

proxy_buffer_size 用来接受后端服务器 response 的第一部分,小的response header 通常位于这部分响应内容里边。默认proxy_buffer_size 被设置成 proxy_buffers 里一个buffer 的大小,当然可以设置更小些。

① 如果 proxy_buffers 关闭

Nginx不会尝试获取到后端服务器所有响应数据之后才返回给客户端,Nginx 会尽快把数据传给客户端,在数据传完之前,Nginx 接收到的最大缓存大小不能超过 proxy_buffer_size 。

② 如果 proxy_buffers 打开

Nginx将会尽可能的读取后端服务器的数据到buffer,直到proxy_buffers设置的所有buffer们被写满或者数据被读取完(EOF),此时Nginx开始向客户端传输数据,会同时传输这一整串buffer们。如果数据很大的话,Nginx会接收并把他们写入到temp_file里去,大小由proxy_max_temp_file_size 控制。「当数据没有完全读完的时候」,Nginx同时向客户端传送的buffer 大小 不能超过 proxy_busy_buffers_size 「此句可能理解有误」。

proxy_busy_buffers_size 的官方解释:

When buffering of responses from the proxied server is enabled, limits the total sizeof buffers that can be busy sending a response to the client while the response is not yet fully read. In the meantime, the rest of the buffers can be used for reading the response and, if needed, buffering part of the response to a temporary file. By default, size is limited by the size of two buffers set by the proxy_buffer_size andproxy_buffers directives.

另外,proxy_buffering 为off 的时候,Nginx 的cache 无效「即 proxy_cache 那一坨命令设置的cache 无效 」 。

文章转载来自:ttlsa.com

上一篇:

下一篇:

相关文章