Nginx响应超时报错:upstream timed out (110: Connection timed out) 原因及解决方案

发布时间:

今天看了下Nginx的日志,发现里面的错误信息upstream timed out (110: Connection timed out) while reading response header from upstream,upstream: "fastcgi://127.0.0.1:9000",大概的意思是等待时间过长,在网上查了很多资料,大意是修改 nginx 配置文件,延长 fastcgi 等待时间,但不能解决根本问题。下面就来给大家解决一下这种问题。

Nginx响应超时报错:upstream timed out (110: Connection timed out) 原因及解决方案
经测试,问题出在 php-fpm,php 代码要使用 file 存取 session,读写数据库,其中有一项操作缓慢,都能造成 nginx 假死;

解决方案:

新建 php-fpm 慢日志:

#mkdir /var/log/php-fpm && chown www-data:www-data /var/log/php-fpm

打开 php-fpm 的配置文件

#vim /usr/local/etc/php-fpm.d/www.conf

修改:

request_slowlog_timeout = 2s
request_terminate_timeout = 30s
slowlog = /var/log/php-fpm/$pool.log.slow

重启 nginx 和 php-fpm

刷新页面,页面一直停留在阻塞状态,没有反应,这时,

tailf /var/log/php-fpm/www.log.slow可以清楚看到执行慢的语句和操作,这样就能找到具体原因!