nginx 问题记录
an upstream response is buffered to a temporary file
报错日志如下,已隐藏不必要的信息,并做了分行处理
2019/10/22 14:52:30 [warn] 6#6:
*137 an upstream response is buffered to a temporary file
/var/cache/nginx/proxy_temp/1/00/0000000001 while reading upstream,
client: 172.19.0.1,
server: ,
request: "GET /1910180934/static/js/vendor.js HTTP/1.1",
upstream: "http://172.19.0.3:80/1910180934/static/js/vendor.js",
host: "example.com",
referrer: "http://example.com/"
其中 an upstream response is buffered to a temporary file,提示了主要信息,文件路径包含 proxy_temp
,说明是 proxy 相关配置不合理,而不是 fastcgi 等配置。 request
则说明了请求文件 1910180934/static/js/vendor.js
,此文件大小为 2.2 MiB,尝试设置 proxy buffer 为 512k,如下配置。
解决方案如下,填写在 nginx.conf
的 http
配置内
# in http part of nginx.conf
proxy_buffer_size 512k;
proxy_buffers 8 512k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
发现任然会报 an upstream response is buffered to a temporary file,继续增大到 1024k,如下配置:
# in http part of nginx.conf
proxy_buffer_size 1024k;
proxy_buffers 8 1024k;
proxy_busy_buffers_size 1024k;
proxy_temp_file_write_size 1024k;
没有再报an upstream response is buffered to a temporary file,配置参考 Nginx Errors-upstream response cache error
nginx gzip 配置
一开始以为在 nginx.conf
文件的 http
部分配置 gizp on
就可以生效了,但是 nginx 的 gzip 默认只对 text/html
有压缩效果,如下是 gzip 的配置,填写到 http
内。
# in http part of nginx.conf
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 7;
gzip_proxied any;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml image/x-icon;
# make sure gzip does not lose large gzipped js or css files
# see http://blog.leetsoft.com/2007/07/25/nginx-gzip-ssl.html
gzip_buffers 16 8k;
# Disable gzip for certain browsers.
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip
: 是否开启 gzipgzip_http_version
: gzip http 版本,防止客户接受数据乱码gzip_comp_level
:压缩等级越高,cpu 使用越高,压缩文件体积越小gzip_types
:如果不指定 js、css 的Content-Type
,就无法对 js,css 文件进行压缩。
其他的压缩配置,请参考 nginx 的官方文档。