当前位置首页 > Nginx知识

nginx超时问题:upstreamtimedout(110:Connectiontimedout)whilereadingre

阅读次数:284 次  来源:admin  发布时间:

目录 错误内容 错误原因 错误解决办法

错误内容

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

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

错误原因

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

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

我们通过定位出错的url,来排查问题,最终确定问题是由于 该请求需要后端处理的时间比较长。

那么解决办法可以是开发人员对该接口进行优化,也可以是我们通过nginx将超时时间设置长些。

错误解决办法

ginx 超时时间设置

官网链接: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,locatio

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.

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

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

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

加上

proxy_read_timeout 240s; 
上一篇:Nginx做web服务器反向代理
下一篇:CentOS7安装MYSQL8.X详细教程