nginx 超时问题: upstream timed out (110: Connection timed out) while reading response header from upstre...

错误内容

我们可以在error.log 里面可以看到

错误内容:upstream timed out (110: Connection timed out) while reading response header from upstream

错误原因

从错误日志我们可以知道,该错误是由于nginx 代理去获取上游服务器的 返回值超时了。那么这个问题是什么导致的:

  1. 该请求获取的数据比较多,后端处理该请求花费的时间较长。
  2. 也可能是代理服务器与上游服务器的网络问题

我们通过定位出错的url,来排查问题,最终确定问题是由于 该请求需要后端处理的时间比较长。
那么解决办法可以是开发人员对该接口进行优化,也可以是我们通过nginx将超时时间设置长些。

错误解决办法

nginx 超时时间设置

官网链接:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout

Syntax:proxy_read_timeout time;
Default:proxy_read_timeout 60s;
Context:http,server,location
Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the proxied server does not transmit anything within this time, the connection is closed.

proxy_read_timeout 参数, 该指令是指从上游服务器两次成功的读操作耗时的超时时间,也就意味着从上游服务器成功读操作后,过了60S,没有再从上游服务器成功读操作的话,就会关闭该连接。

默认值是 60s ,我们可以设置为240s,或者300s。来应对上游服务器处理请求慢的问题。

在nginx 的配置文件 在 http,server,location 三个位置任意一个位置
加上

proxy_read_timeout 240s; 

转载于:https://www.cnblogs.com/operationhome/p/10190160.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值