现象
nginx后端代理为报表服务,错误日志大量出现上游服务超时,页面访问也会出现504返回,查看后发现服务本身没问题,问题着重在nginx本身,报表服务本身属于大查询,返回较慢。nginx默认本身后端超时为60S,大查询的返回大于60S所以会有几率出现504请求失败
报错
2022/08/05 13:00:24 [error] 3389#e: *1092213 upstream timed out (110: Connection timed out) while reading upstream, client: 10.6. 18.19, server: localhost, request: “POST /rcenter/rpt/api/showReport HTTP/1.1”, upstream: “http://10.6.6.65:8880/rcenter/rpt/api/showReport” host: “10.6.6.67”
处理
增加后端超时时长参数
参数 | 详解 |
---|---|
proxy_connect_timeout | 与后端/上游服务器建立连接的超时时间 |
proxy_send_timeout | 与后端/上游服务器发送请求的超时时间 |
proxy_read_timeout | 与后端/上游服务器读取响应的超时时间 |
server {
listen 80;
server_name localhost;
location / {
root html;
proxy_pass http://report;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;