nginx+tomcat 报错:『an upstream response is buffered to a temporary file 』

一、过程描述:

访问新项目网站发现有静态资源获取failed,图片经常无法显示,刷新偶尔图片能显示出来。

查看nginx日志,有error.log报错:

【2017/07/21 22:53:12 [warn] 22402#0: *484 an upstream response is buffered to a temporary file /var/tmp/nginx/proxy//6/01/0000000016 while reading upstream, client: 106.121.13.193, server: wap.wagonsclub.com, request: "GET /source/images/applyfristbg.jpg HTTP/1.1", upstream: "http://127.0.0.1:8081/source/images/applyfristbg.jpg", host: "wap.wagonsclub.com", referrer: "http://wap.wagonsclub.com/source/css/apply-first-7ae1ca00a910468d350b293787c7e95dfbebd675.css”】

二、经研究得知:

1、是因为nginx默认的buffer太小,请求头header太大时会出现缓存不足,写入到了磁盘中,造成访问中断。

2、进而联系前端得知前端为了SEO,在header中加入和不少的中文词汇,header那叫一个大。。。

三、解决办法:

因为nginx+tomcat中,nginx做的proxy,就是反向代理,所以在nginx+tomcat模式中,修改fastcgi_buffer_* 是无效的,需要修改proxy对应的buffer大小。

1、对于( php | python )+nginx的可以设置为:

fastcgi_buffer_size 512k;

fastcgi_buffers 6 512k;

fastcgi_busy_buffers_size 512k;

fastcgi_temp_file_write_size 512k;

2、对于tomcat+nginx的可以设置为:

proxy_buffering    off;     #开启从后端被代理服务器的响应内容缓冲

proxy_buffer_size  128k;     #设置缓冲区的大小和数量

proxy_buffers 100  128k;     #

client_max_body_size 100m;

对于实际修改的大小,需要按实际情况来。

三、网上查询的原理:

buffer工作原理

首先第一个概念是所有的这些proxy buffer参数是作用到每一个请求的。每一个请求会安按照参数的配置获得自己的buffer。proxy buffer不是global而是per request的。

proxy_buffering 是为了开启response buffering of the proxied server,开启后proxy_buffers和proxy_busy_buffers_size参数才会起作用。

无论proxy_buffering是否开启,proxy_buffer_size(main buffer)都是工作的,proxy_buffer_size所设置的buffer_size的作用是用来存储upstream端response的header。

在proxy_buffering 开启的情况下,Nginx将会尽可能的读取所有的upstream端传输的数据到buffer,直到proxy_buffers设置的所有buffer们被写满或者数据被读取完(EOF)。此时nginx开始向客户端传输数据,会同时传输这一整串buffer们。同时如果response的内容很大的话,Nginx会接收并把他们写入到temp_file里去。大小由proxy_max_temp_file_size控制。如果busy的buffer传输完了会从temp_file里面接着读数据,直到传输完毕。

一旦proxy_buffers设置的buffer被写入,直到buffer里面的数据被完整的传输完(传输到客户端),这个buffer将会一直处在busy状态,我们不能对这个buffer进行任何别的操作。所有处在busy状态的buffer size加起来不能超过proxy_busy_buffers_size,所以proxy_busy_buffers_size是用来控制同时传输到客户端的buffer数量的。

时间: 2024-09-28 22:10:53

nginx+tomcat 报错:『an upstream response is buffered to a temporary file 』的相关文章

Nginx an upstream response is buffered to a temporary file

1.错误日志:warn:an upstream response is buffered to a temporary file 解决办法:增加fastcgi_buffers 8 4K;     fastcgi_buffer_size 4K; 2. a client request body is buffered to a temporary file 解决办法:增加client_max_body_size 2050m;     client_body_buffer_size 1024k; N

Nginx warn:an upstream response is buffered to a temporary file

我通过nginx下载文件,error.log中出现如下警告日志:warn:an upstream response is buffered to a temporary file  . 虽然网上各种例子都是通过增加fastcgi_buffers       和fastcgi_buffer_size来解决此问题. 然而,buffer总有到顶的时候. 通过搜索,以下这篇文章讲的最透彻. 记一次下载大文件存在数据异常问题排查 原文地址:https://www.cnblogs.com/huanghong

an upstream response is buffered to a temporary file

今天调试nginx+tomcat 在登录的时候 某个用户无法调用,查看nginx报错如下: 经网络查询 发现是请求头过大导致,修改nginx配置文件即可 fastcgi_buffer_size 512k;fastcgi_buffers 6 512k;fastcgi_busy_buffers_size 512k;fastcgi_temp_file_write_size 512k;

Nginx启动报错:

Nginx启动报错:10013: An attempt was made to access a socket in a way forbidden 2014-08-07 14:39:10   来源:   评论:0 点击: Nginx在win7,win2008下启动报错:bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permis

eclipse中以debug方式启动tomcat报错

在eclipse中debug  Tomcat报错,错误如下: FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197) ERROR: transport error 202: connect failed: Operation timed out ERROR: JDWP Transport dt_socket failed to initiali

TOMCAT报错:HTTP Status 404 -

构建struts2工程师,tomcat报错: HTTP Status 404 - type Status report message description The requested resource is not available. Apache Tomcat/6.0.37

Nginx启动报错:10013: An attempt was made to access a socket in a way forbidden

Nginx在win7,win2008下启动报错:bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions) . 原因是Win7下nginx默认80端口被System占用,造成nginx启动报错的解决方案. 在cmd窗口运行如下命令: [plain] C:\Users\Administrator>netstat -ao

解决tomcat报错javax.imageio.IIOException: Can't create output stream!

启动tomcat catalina.out报错如下,登陆的时候无法显示验证码 2017-06-09 11:23:06,628 DEBUG org.springframework.web.servlet.DispatcherServlet 845 - DispatcherServlet with name 'spring-mvc' processing GET request for [/data-analysis/kaptchaImage.do]2017-06-09 11:23:06,629 D

【转】Eclipse下启动tomcat报错:/bin/bootstrap.jar which is referenced by the classpath, does not exist.

转载地址:http://blog.csdn.net/jnqqls/article/details/8946964 1.错误: 在Eclipse下启动tomcat的时候,报错为:Eclipse下启动tomcat报错:The archive: C:/Program Files(x86)/Java/jdk1.7.0_10/lib/tools.jar which is referenced by the classpath, doesnot exist. 2.原因: 这是因为我中途移动过tomcat的位