售前咨询
技术支持
渠道合作

Nginx+PHP-FPM环境访问网站出现502错误的优化方法 – Nginx

游戏后端代码采用Nginx+PHP-FPM的方式部署。放问游戏的时候偶尔会出现502错误。

Nginx错误日志出现以下日志

2014/07/05 17:20:58 [error] 18431#0: *148739 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.56, server: , request: “POST /gateway.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “”

现列出排查思路

在/etc/php.ini中设置PHP脚本执行的最长时间max_execution_time = 30,这里设置为30秒。

在/etc/php-fpm.conf 中设置PHP-FPM进程处理每个进程的超时时间request_terminate_timeout = 30s

在/etc/php-fpm.conf中开启PHP的慢日志

request_slowlog_timeout = 1s

slowlog = /var/log/php-fpm/www-slow.log

在Nginx配置文件nginx.conf 中设置

fastcgi_connect_timeout 60; 设置Nginx和FastCGI Server建立连接的超时时间,默认是60秒,但是这个值不能经常超过75秒

fastcgi_send_timeout 60;    设置Nginx传送请求到FastCGI Server的超时时间

fastcgi_read_timeout 60;    设置FastCGI Server读取请求的超时时间

上一篇:

下一篇:

相关新闻

 

领取优惠
免费预约

申请试用SSL证书

提交成功!

咨询客服