首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CGI >

nginx php fastcgi Connection reset by peer的原因及解决方法

2012-06-29 
nginx php fastcgi Connection reset by peer的原因及解决办法Connection reset by peer这个错误是在nginx

nginx php fastcgi Connection reset by peer的原因及解决办法

Connection reset by peer

这个错误是在nginx的错误日志中发现的,为了更全面的掌握nginx运行的异常,强烈建议在nginx的全局配置中增加

error_log?? logs/error.log notice;

这样,就可以记录nginx的详细异常信息。



nginx的错误日志中会出现Connection reset by peer) while reading response header from upstream, client: 1.1.1.1, server: 102.local, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000


后来反复检查,发现这是因为php运行较慢,并超出php-fpm.conf的request_terminate_timeout设置的秒数。


request_terminate_timeout用于设置当某个php脚本运行最长时间,若超出php-fpm进程管理器强行中止当前程序,并关闭fastcgi和nginx的网络连接,然后nginx中就会出现Connection reset by peer的错误了。


也就是说,产生这个错误的原因是:

php 程序的运行时间超出request_terminate_timeout设置的值。

在php-fpm环境下,在php的安装目录的etc/php-fpm.conf中有此值的设置项,可将其设置为0或更大的值。


提示,在php.ini中存在一项max_execution_time,也用于设置php脚本的最长执行时间。但在php-fpm环境下,我发现max_execution_time的设置是无效的,只有request_terminate_timeout产生了作用。


总结:请将request_terminate_timeout设置为较大的值或0,可减少因php脚本执行时行过长导致nginx产生Connection reset by peer错误。

热点排行