错误内容
我们可以在error.log 里面可以看到
错误内容:upstream timed out (110: Connection timed out) while reading response header from upstream
错误原因
从错误日志我们可以知道,该错误是由于nginx 代理去获取上游服务器的 返回值超时了。那么这个问题是什么导致的:
- 该请求获取的数据比较多,后端处理该请求花费的时间较长。
- 也可能是代理服务器与上游服务器的网络问题
我们通过定位出错的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,location 三个位置任意一个位置
加上
proxy_read_timeout 240s;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。