CS入门技能树Linux入门初识Linux27216 人正在系统学习中
来自 https://blog.csdn.net/Zisson_no_error/article/details/119796369
如何修复 nginx 上游响应缓冲到临时文件错误
05/08/2017 提示与技巧 发表评论
运行 Nginx 一段时间后。您可以阅读我如何 在 Centos 上使用 Linux、Nginx、PHP-FPM 和 MySQL 安装 LEMP 服务器。我从 Centos 上的 nginx 收到大量警告日志,上游响应被缓冲到一个我不喜欢看到的临时文件。问题是我没有为 nginx 设置 fastcgi_buffer 所以 nginx 发出警告上游响应被缓冲到临时文件 /var/cache/nginx/fastcgi_temp/。
查看Nginx的错误日志
# cat /var/log/nginx/error.log
有许多上游响应缓冲到临时文件 /var/cache/nginx/fastcgi_temp/ 来自 forum.namhuy.net 的警告日志。警告消息表示响应已缓冲到磁盘。这不是那么重要的问题,但我不想出现任何错误。您可以在 .conf 文件中使用“fastcgi_max_temp_file 0”禁用磁盘缓冲或设置 fastcgi_buffers 和 fastcgi_buffer_size
2014 / 05 / 10 03 : 56 : 06 [ warn ] 1483 #0: *144520 在读取上游时,上游响应被缓冲到临时文件 /var/cache/nginx/fastcgi_temp/5/78/0000003785,客户端:54.86。 133.62,服务器:forum.namhuy.net,请求:“GET /style.php?id=1&lang=en&sid=69475f2bd936d3e96ef925ce546a79c9 HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”,主机:“论坛。 namhuy.net", referrer: "http://forum.namhuy.net/viewforum.php?f=3&sid=74d333aafeefe7332a418519e8b03277"
2014 / 05 / 10 03 : 56 :28 [警告] 1483#0: *144518 上游响应缓冲到临时文件 /var/cache/nginx/fastcgi_temp/6/78/0000003786 读取上游时,客户端:54.86.133.62,服务器:forum.namhuy.net,请求:“GET /style.php?id=1&lang=en HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "forum.namhuy.net", referrer: "http://forum.namhuy. net/posting.php?
mode = post & f =3&sid=69475f2bd936d3e96ef925ce546a79c9 " 2014 / 05 / 10 03:57:40 [警告] 1483 #0: *144673 上游响应缓冲到临时文件 /var/cache/nginx/fastcgi_temp/7/78/0000003787 读取上游时,客户端:198.204.244.53,服务器:forum.namhuy.net,请求:“GET /style.php?id=1&lang=en&sid=b70a193e6808fb2183ac1c0228097227 HTTP/1.1",上游:"fastcgi://127.0.0.1:9000",主机:"forum.namhuy.net",引用者:"http://forum.
namhuy.net/viewforum.php?f=2&sid=74d333aafeefe7332a418519e8b03277 " 2014 / 05 / 10 03:58:06 [警告] 6276 _ _ _ #0: *37 在读取上游时,上游响应被缓冲到临时文件 /var/cache/nginx/fastcgi_temp/1/00/0000000001,客户端:198.204.244.53,服务器:forum.namhuy.net,请求:“GET /style.php?id=1&lang=en HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "forum.namhuy.net", referrer: "http://forum.namhuy. net/viewtopic.php?f=2&t=2&sid=b70a193e6808fb2183ac1c0228097227"
禁用 fastcgi 磁盘缓冲
# nano /etc/nginx/conf.d/default.conf
并将此行添加到 location ~ \.php$ { fastcgi configurations }
fastcgi_max_temp_file 0;
你应该有这样的东西
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_max_temp_file 0;
include fastcgi_params;
}
To set fastcgi_buffer_size and fastcgi_buffer
# nano /etc/nginx/conf.d/default.conf
and add this two lines to location ~ \.php$ { fastcgi configurations }
fastcgi_buffer_size 4K;
fastcgi_buffers 64 4k;
You should have something look like this
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_max_temp_file 0;
fastcgi_buffer_size 4K;
fastcgi_buffers 64 4k;
include fastcgi_params;
}
Fastcgi buffer will store responses up to 4K+64*4K=260K in memory.
来自 https://itbeginner.net/fix-nginx-upstream-response-buffered-temporary-file-error/
描述
NGINX Plus 错误日志包含如下警告:
2020/01/01 11:11:54 [warn] 1234#1234: *123 在读取上游时,上游响应被缓冲到临时文件 /var/cache/nginx/proxy_temp/1/00/0000000001,客户端:xxx。 xxx.xxx.xxx,服务器:example.com,请求:“GET /image.png HTTP/1.1”,上游:“ http://127.0.0.1:8080/image.png ”,主机:“ example.com ” , 推荐人:“ http://example.com ”
环境
原因
警告消息表明响应已缓冲到磁盘,因为它不适合配置的内存缓冲区。
建议的操作
根据您的用例,您有三个选项:
选项 1:增加缓冲区
您可以调整缓冲区以适应完整的上游响应。如果最大可能的响应大小未知,我们建议将两个参数都增加两倍,直到警告停止出现。
proxy_buffers 16 16k;
proxy_buffer_size 16k;
根据官方文档,默认值为proxy_buffers
8 4k/8k (取决于平台),而proxy_buffers_size
. 它由默认内存页面大小决定(要找出它,只需运行getconf PAGESIZE
)。
选项 2:禁用缓冲
设置proxy_buffering
为关闭。
如果响应太大(例如,5 GB 的电影),您可以完全禁用响应缓冲以将响应直接流式传输到客户端。
proxy_buffering off;
默认值为on。将其设置为off,会将响应直接流式传输到客户端。虽然不推荐!
选项 3:忽略这些警告
您至少可以什么都不做,但要留意关键的服务器性能指标:CPU、磁盘 I/O和内存。这些警告是无害的,您可以忽略它们,除非您发现磁盘 I/O 使用率很高。 来自 https://my.f5.com/manage/s/article/K48373902
问题描述
我在访问静态资源(js、css 等)时总是收到以下警告,有什么方法可以设置它来解决问题。
an upstream response is buffered to a temporary file /usr/local/apisix/proxy_temp/6/85/0000116856 while reading upstream, client
这是因为 Nginx 上游模块默认具有非零临时文件大小配置:
语法:proxy_max_temp_file_size 大小;
默认值:
proxy_max_temp_file_size 1024m;
上下文:http,服务器,位置
当启用代理服务器的响应缓冲,并且整个响应不适合由 proxy_buffer_size 和 proxy_buffers 指令设置的缓冲区时
,部分响应可以保存到临时文件中。该指令设置临时文件的最大大小。一次写入临时文件的数据大小由
proxy_temp_file_write_size 指令设置。
零值禁用对临时文件的响应缓冲。
所以当请求超出内存缓冲区时,数据将被保存到文件中。
别担心,这不是问题。
来自 https://github.com/apache/apisix/issues/3020