Nginx Buffer 简记 - Nginx Proxy 相关Buffer性质与配置关系 - proxy_buffer_size - proxy_buffers - proxy_busy_buffers_size

  |   0 评论   |   2,099 浏览

本文对Nginx的HTTP请求的各个阶段涉及到的缓存(Buffer)相关的配置进行了简单的梳理.
关键字: proxy_buffer_size , proxy_buffering, proxy_buffers , proxy_busy_buffers_size .
看完本文后, 你会对Nginx的请求缓存以及Response缓存有一个基本的了解.

  1. proxy_buffer_size 用于设置 upstream的header的缓存.
  2. proxy_buffers 用于设置 upstream的response的body(可能不准确)的缓存个数与大小.
  3. proxy_busy_buffers_size 用于设置可用于处于发送busy状态的缓存区大小. 其值最小值必须大于等于 max(proxy_buffer_size,proxy_buffers one buffer size),且必须小于 (proxy_buffers-1)*size
# nginx: [emerg] "proxy_busy_buffers_size" must be less than the size of all "proxy_buffers" minus one buffer
# nginx: [emerg] "proxy_busy_buffers_size" must be equal to or greater than the maximum of the value of "proxy_buffer_size" and one of the "proxy_buffers"

WeChatWorkScreenshot2ec495a7d4934fff95b93ad0ade7be98.png

proxy_buffer_size

一句话总结: 用于缓冲 upstream_server 返回的第一部分, 即: Header

Syntax:proxy_buffer_size size;
Default:proxy_buffer_size 4k|8k;
Context:http, server, location

Sets the <i>size</i> of the buffer used for reading the first part of the response received from the proxied server. This part usually contains a small response header. By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform. It can be made smaller, however.

翻译:
设置缓冲区的大小用来读取从代理服务器收到的响应的第一部分。这部分通常包含一个小的响应头(Header)。默认情况下,此缓冲区大小等于1个page。这是4 k或8 k,取决于平台。然而,它可以做得更小。

proxy_buffering

一句话总结: 用于缓存upstream_server的 返回的response body的开关. 使能或者禁止.

Syntax:proxy_buffering on | off;
Default:proxy_buffering on;
Context:http, server, location

Enables or disables buffering of responses from the proxied server.

When buffering is enabled, nginx receives a response from the proxied server as soon as possible, saving it into the buffers set by the proxy_buffer_size and proxy_buffers directives. If the whole response does not fit into memory, a part of it can be saved to a temporary file on the disk. Writing to temporary files is controlled by the proxy_max_temp_file_size and proxy_temp_file_write_size directives.

When buffering is disabled, the response is passed to a client synchronously, immediately as it is received. nginx will not try to read the whole response from the proxied server. The maximum size of the data that nginx can receive from the server at a time is set by the proxy_buffer_size directive.

Buffering can also be enabled or disabled by passing “yes” or “no” in the “X-Accel-Buffering” response header field. This capability can be disabled using the proxy_ignore_headers directive.

翻译:

开启或者禁止 被代理服务器的Reponse缓存功能.

当缓冲被启用时,nginx会尽快接收到来自代理服务器的响应,并将其保存到proxy_buffer_sizeproxy_buffers指令设置的缓冲区中。如果整个响应不能完整装入内存,则可以将其中一部分保存到磁盘上的临时文件中。写入临时文件由proxy_max_temp_file_sizeproxy_temp_file_write_size指令控制。

缓冲被禁用时,response在收到后立即同步传递给客户端。Nginx不会尝试从代理服务器读取整个响应。nginx一次可以从服务器接收的数据的最大大小是由proxy_buffer_size指令设置的.

缓冲也可以通过在“x - accelerate -Buffering”响应报头字段中传递“yes”或“no”来启用或禁用。可以使用proxy_ignore_headers指令禁用此功能。

proxy_buffers

一句话总结: 用于控制 upstream_serverresponse_body 的缓存配置. 且是针对每一个链接, 配置缓存数量和缓存大小.

Syntax:proxy_buffers number size;
Default:proxy_buffers 8 4k|8k;
Context:http, server, location

Sets the <i>number</i> and <i>size</i> of the buffers used for reading a response from the proxied server, for a single connection. By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform.

翻译:
为单个连接设置用于从代理服务器读取响应的缓冲区的数量和大小。默认情况下,缓冲区大小等于一个内存页。这是4K或8K,取决于平台。

proxy_busy_buffers_size

一句话总结. 用于控制用于缓存upstream_server的缓存request_body 的缓冲区的整体数量中,可同时用于发送busy的缓冲区size. 剩余的可用于接收upstream的response body.

Syntax:proxy_busy_buffers_size size;
Default:proxy_busy_buffers_size 8k|16k;
Context:http, server, location

When buffering of responses from the proxied server is enabled, limits the total <i>size</i> of 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, <i>size</i> is limited by the size of two buffers set by the proxy_buffer_size and proxy_buffers directives.

翻译:
当启用了代理服务器的响应缓冲时,限制在响应尚未完全读取时忙于向客户端发送响应的缓冲区的总大小。与此同时,其余缓冲区可用于读取响应,如果需要,还可将部分响应缓冲到临时文件中。默认情况下,大小受proxy_buffer_sizeproxy_buffers指令设置的两个缓冲区的大小限制。

评论

发表评论


取消