NGINX学习笔记——配置缓冲

原文地址:https://www.nginx.com/resources/admin-guide/reverse-proxy/
原文标题:Configuring Buffers

默认情况,NGINX缓冲来自被代理服务器的响应。
By default NGINX buffers responses from proxied servers.

响应被保存在内部缓冲区,知道所有的响应都接收完才发送给客户端。缓冲帮助优化了慢客户端的性能,如果NGINX将响应同步发送给客户端,会浪费被代理服务器的时间。然而,当启用了缓冲,NGINX允许被代理服务器快速处理响应,NGINX会保存响应知道客户端下载完成。
A response is stored in the internal buffers and is not sent to the client until the whole response is received. Buffering helps to optimize performance with slow clients, which can waste proxied server time if the response is passed from NGINX to the client synchronously. However, when buffering is enabled NGINX allows the proxied server to process responses quickly, while NGINX stores the responses for as much time as the clients need to download them.

负责开启和关闭缓冲功能的指令是proxy_buffering。默认这个值是on也就是启用缓冲功能。
The directive that is responsible for enabling and disabling buffering is proxy_buffering. By default it is set to on and buffering is enabled.

proxy_buffers指令控制分配给一个请求的缓冲大小和数量。从被代理服务器返回的第一部分响应被保存在单独的缓冲区,这个缓冲区的大小用proxy_buffer_size控制。这部分通常包含一个相当小的响应头,可以比其余的响应使用的缓冲更小。
The proxy_buffers directive controls the size and the number of buffers allocated for a request. The first part of the response from a proxied server is stored in a separate buffer, the size of which is set with the proxy_buffer_size directive. This part usually contains a comparatively small response header and can be made smaller than the buffers for the rest of the response.

在下面的例子中,增加了缓冲的默认数量,第一部分的缓冲大小也比默认值更小了。
In the following example, the default number of buffers is increased and the size of the buffer for the first portion of the response is made smaller than the default.

location /some/path/ {
    proxy_buffers 16 4k;
    proxy_buffer_size 2k;
    proxy_pass http://localhost:8000;
}

如果缓冲被禁用,一旦收到被代理服务器的响应就会同步发送给客户端。快速交互的客户端,希望尽快收到服务器的响应,会需要这种行为。
If buffering is disabled, the response is sent to the client synchronously while it is receiving it from the proxied server. This behavior may be desirable for fast interactive clients that need to start receiving the response as soon as possible.

要在特定的location禁用缓冲,将location中的proxy_buffering指令设置为off,如下:
To disable buffering in a specific location, place the proxy_buffering directive in the location with the off parameter, as follows:

location /some/path/ {
    proxy_buffering off;
    proxy_pass http://localhost:8000;
}

这种情况,NGINX仅仅使用由proxy_buffer_size设置的缓冲保存响应的当前部分。
In this case NGINX uses only the buffer configured by proxy_buffer_size to store the current part of a response.

你可能感兴趣的:(架构设计,Linux)