nginx recv() failed (104: Connection reset by peer) while reading response header from upstream解决方法

最近发现LNMP环境在运行雅黑探针的时候报错,查了Nginx的错误日志为:

2018/10/06 15:37:30 [error] 1123#0: *4149 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /t.php?act=rt&callback=jQuery172003508052623214475_1538811294779&_=1538811449347 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "gc.fdsyy.net", referrer: "http://gc.fdsyy.net/t.php"

百度一下普遍的解决方法:

不要使用php-fpm默认的request_terminate_timeout,最好设成request_terminate_timeout=0;

vi /etc/php5/fpm/pool.d/www.conf

request_terminate_timeout=0;

php程序执行时间超过php-fpm.conf中request_terminate_timeout设置的默认值,然后php-fpm进程立即退出,
此时nginx得不到php-fpm进程的正确结果,响应502

增加进程数

pm.max_requests = 500

Google搜索解决方案有两种:

第一种方案是

I finally found a reference to fastcgi and a 502 bad gateway error (https://support.plesk.com/hc/en-us/articles/213903705). That lead me to look for a buffer size limit in the uwsgi configuration which exists as buffer-size. The default value is 4096. From the documentation, it says:

If you plan to receive big requests with lots of headers you can increase this value up to 64k (65535).

edit php.ini:

output_buffering = 65535

第二种方案推荐重新安装PHP

You need to re-install PHP:

apt-get install –reinstall php5-fpm

考虑到我的php是之前安装Apache的时候安装的php,因此,我采取了重新安装php的解决方案,没想到居然解决了这个问题,Nginx错误日志里没有再次报错了。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注