tengine常见错误码总结以及原因分析,tengine常见错误


403 Forbidden

You don’t have permission to access the URL on this server. Sorry for the inconvenience.
Please report this message and include the following information to us.

解决:看下权限文件权限

500

该网页无法正常运作
www.test.com 目前无法处理此请求。
HTTP ERROR 500

原因:

复现场景:

php.ini配置:

max_execution_time = 5    ; Maximum execution time of each script, in seconds

php-fpm配置:

request_terminate_timeout = 30

php_code:

$start = time();
while(true) {
   if (time()-$start > 5) {
 		die("game over");
 	}
}

解决办法:

504 Gateway Time-out

The gateway did not receive a timely response from the upstream server or application. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!

复现场景:

PHP 代码:

<?php
	sleep(11);
	echo 'hello world';	
?>

tengine设置:

// fastcgi连接超时时间,默认60秒
fastcgi_connect_timeout 10;

// tengine 进程向 fastcgi 进程发送请求过程的超时时间
fastcgi_send_timeout 10;

//fastcgi 进程向 tengine 进程发送输出过程的超时时间
fastcgi_read_timeout 10;

原因之一:导致网关超时的原因程序执行时间较长超过了tengine设置的超时时间导致网关超时

解决办法:

502 Bad Gateway

The proxy server received an invalid response from an upstream server. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!

复现场景:

php.ini配置:

max_execution_time = 30     ; Maximum execution time of each script, in seconds

php-fpm配置:

request_terminate_timeout = 10

php代码:

<?php
	sleep(11);
	echo 'hello world';	
?>

执行后tengine的日志

2018/09/21 15:01:50 [error] 32753#0: *8 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.33.65.83, server: www.test.com, request: "GET /a.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:8721", host: "www.test.com"

php-fpm 日志:

[21-Sep-2018 16:57:43] WARNING: [pool test] child 824, script '/home/test/www/htdocs/a.php' (request: "GET /a.php") executing too slow (3.963645 sec), logging
[21-Sep-2018 16:57:43] NOTICE: child 824 stopped for tracing
[21-Sep-2018 16:57:43] NOTICE: about to trace 824
[21-Sep-2018 16:57:43] NOTICE: finished trace of 824
[21-Sep-2018 16:57:44] WARNING: [pool test] child 824, script '/home/test/www/htdocs/a.php' (request: "GET /a.php") execution timed out (4.964827 sec), terminating
[21-Sep-2018 16:57:44] WARNING: [pool test] child 824 exited on signal 15 (SIGTERM) after 683.779281 seconds from start
[21-Sep-2018 16:57:44] NOTICE: [pool test] child 838 started

从php-fpm日志我们可以看到请求给了824进程,但是由于脚本执行的时间超过了request_terminate_timeout的时间,导致824收到了退出信号(实际上是master进程发出的),824退出后新启动了838进程。

看来如果php-fpm的worker进程执行超时(超过request_terminate_timeout),不仅终止脚本执行,而且worker进程也会退出。随后会启动一个新的进程,本次502的原因可能就是tengine的报错连接被重置是因为php的worker进程退出了

原因:

(简而言之:php-fpm进程数不够用、php执行时间长、或者是php-fpm进程死掉,都会出现502错误。)

解决办法:

499

主要是客户端请求时间超过了(客户端设置超时时间,例如当CURL调用服务端api的时候)
一般遇到这种情况考虑

(番外)PHP读取数据库的最大执行时间:

php.ini配置

mysqlnd.net_read_timeout = 5 

PHP读取数据库的最大执行时间
如果超时 一般会报 Mysql server has gone away

参考资料:
https://blog.tanteng.me/2016/03/nginx-buffer-params/
https://www.cnblogs.com/leezhxing/p/6220879.html

相关内容

    暂无相关文章