nginx 问题记录

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.confhttp 配置内

# 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: 是否开启 gzip
  • gzip_http_version: gzip http 版本,防止客户接受数据乱码
  • gzip_comp_level:压缩等级越高,cpu 使用越高,压缩文件体积越小
  • gzip_types:如果不指定 js、css 的 Content-Type,就无法对 js,css 文件进行压缩。

其他的压缩配置,请参考 nginx 的官方文档。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值