upstream timed out (110: Connection timed out) while reading response header from upstream, client:

时间:2023-03-09 01:02:42
upstream timed out (110: Connection timed out) while reading response header from upstream, client:

遇到的问题

之前没配置下面这段,访问时候偶尔会出现 504 gateway timeout,由于偶尔出现,所以不太好排查

proxy_connect_timeout 300s;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_ignore_client_abort on;

报错日志:

...upstream timed out (110: Connection timed out) while reading response header from upstream, client: ...(后面的省略)

从日志看来是连接超时了,网上一通乱查之后估计可能是后端服务器响应超时了,本着大胆假设,小心求证的原则,
既然假设了错误原因就要做实验重现错误:那就调整代理超时参数,反过来把代理超时阀值设小(比如 1ms)看会
不会次次出现 504。后来发现把 proxy_read_timeout 这个参数设置成 1ms 的时候,每次访问都出现 504。于是把这
个参数调大,加入上面那段配置,解决问题了。