当前位置:   article > 正文

tengine常见错误码总结以及原因分析_sorry for the inconvenience. please report this me

sorry for the inconvenience. please report this message and include the foll

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

原因:

  1. web脚本错误,如php语法错误,lua语法错误等。
  2. 访问量大的时候,由于系统资源限制,而不能打开过多的文件句柄
  3. 脚本执行时间在(max_execution_time, request_terminate_timeout]之间,超过(request_terminate_timeout)的情况下面有介绍

复现场景:

php.ini配置:

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

  • 1
  • 2

php-fpm配置:

request_terminate_timeout = 30
  • 1

php_code:

$start = time();
while(true) {
   if (time()-$start > 5) {
 		die("game over");
 	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

解决办法:

  1. 保证代码的正确性
  2. 正确设置max_execution_time 和 request_terminate_timeout
  3. 如果需要执行耗时较长的脚本又不想修改php.ini可以添set_time_limit(0);

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';	
?>
  • 1
  • 2
  • 3
  • 4

tengine设置:

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

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

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

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

解决办法:

  1. 优化代码(这个是关键)
  2. 调整tengine超时时间
    (如果是代理调整proxy_connect_timeout,proxy_send_timeout,proxy_read_timeout)

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
  • 1

php-fpm配置:

request_terminate_timeout = 10
  • 1

php代码:

<?php
	sleep(11);
	echo 'hello world';	
?>
  • 1
  • 2
  • 3
  • 4

执行后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"
  • 1

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

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

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

原因:

  1. 脚本执行的时间超过了request_terminate_timeout的时间导致产生502
  2. 后台worker数目负载大或者过少,导致新来的请求没有worker处理导致502
  3. 由大量warning引起(https://mp.weixin.qq.com/s/-3XBN1_ru2jF3P-rakOjKg)
  4. php.ini 的 memory_limit 过小【待考证】
  5. php-fpm.conf 中 max_children、max_requests 设置不合理【待考证】
    (简而言之:php-fpm进程数不够用、php执行时间长、或者是php-fpm进程死掉,都会出现502错误。)

解决办法:

  1. 合理修改request_terminate_timeout
  2. 合理设置pm.max_children, pm.start_servers, pm.min_spare_servers,pm.max_spare_servers, pm.max_requests

499

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

  1. 服务端有慢查询导致客户端请求超时
  2. 合理调整客户端超时时间

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

php.ini配置

mysqlnd.net_read_timeout = 5 
  • 1

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

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

推荐资料:
https://blog.csdn.net/Mijar2016/article/details/53709777

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/679514
推荐阅读
相关标签
  

闽ICP备14008679号