如何正确设置fastcgi_busy_buffers_size?

如何正确设置fastcgi_busy_buffers_size?

我在单个 VPS 服务器上运行了几个 wordpress 网站。

[emerg] "fastcgi_busy_buffers_size" must be less than the size of all "fastcgi_buffers" minus one buffer in /etc/nginx/nginx.conf:112"当我检查 nginx -t 时,我看到错误。

我将 fastcgi_buffers 大小设置为如下所示的每个服务器块。

fastcgi_buffers 64 16k; # default 8 4k
fastcgi_buffer_size 32k;

并且我28 ~ 32k 在 nginx.conf 上测试了 fastcgi_busy_buffers_size。

但无论我放什么,我都找不到相同的值。

Nginx 不断收到以下错误:

 [emerg] "fastcgi_busy_buffers_size" must be less than the size of all "fastcgi_buffers" minus one buffer in /etc/nginx/nginx.conf:112

 [emerg] "fastcgi_busy_buffers_size" must be equal to or greater than the maximum of the value of "fastcgi_buffer_size" and one of the "fastcgi_buffers" in /etc/nginx/nginx.conf:112

有人能告诉我是否有办法设置正确的 fastcgi_busy_buffers_size 值吗?

谢谢。

答案1

[emerg] "fastcgi_busy_buffers_size" must be less than the size of all "fastcgi_buffers" minus one buffer in /etc/nginx/nginx.conf:112
[emerg] "fastcgi_busy_buffers_size" must be equal to or greater than the maximum of the value of "fastcgi_buffer_size" and one of the "fastcgi_buffers" in /etc/nginx/nginx.conf:112

fastcgi_buffer_size规定每个 FastCGI 请求将分配多少内存来容纳其第一个响应流(通常是 FastCGI 响应标头)。此缓冲区已满后,FastCGI 缓冲区将转移到 分配的任何内容fastcgi_buffers

fastcgi_buffers规则根据请求使用多少个内存块及其大小来缓冲其余响应。

fastcgi_busy_buffers_sizefastcgi_buffers规定有多少内存可以主动向客户端发送响应,并且这个值与和绑定fastcgi_buffer_size,其中它应该是:

  • fastcgi_buffer_size等于或大于和一个块之间的最大值fastcgi_buffers(用于将 FastCGI 响应发送到客户端的最小繁忙缓冲区)

    fastcgi_busy_buffers_size >= max(fastcgi_buffer_size, fastcgi_buffers[size])
    
  • 小于全部fastcgi_buffers减一(仍然将 FastCGI 响应数据发送到客户端,但您需要留下一些块fastcgi_buffers以容纳上游响应的写入)

    fastcgi_busy_buffers_size < (fastcgi_buffers[count] - 1) * fastcgi_buffers[size]
    

使用您的配置:

fastcgi_buffers 64 16k; # default 8 4k
fastcgi_buffer_size 32k;

您的fastcgi_busy_buffers_size范围应在max(32k, 16k) = 32k(含) 到(64 - 1) * 16k = 1008k(不含) 之间。

此外,您可能希望将缓冲区与操作系统的页面大小对齐,以优化内存使用情况并避免碎片化。

相关内容