X
X
X
X

知识库

主页知识库宝塔相关问题502报错 网络异常

502报错 网络异常

1.状态码的RFC说明

502Bad Gateway
The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.
作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应

504Gateway Time-out
The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access in attempting to complete the request.
Note: Note to implementors: some deployed proxies are known to return 400 or 500 when DNS lookups time out.
作为网关或者代理工作的服务器尝试执行请求时,未能及时从上游服务器(URI标识出的服务器,例如HTTP、FTP、LDAP)或者辅助服务器(例如DNS)收到响应。

2.具体原因分析

nginx返回502,是收到了服务理解的相应
1. nginx和php-fpm无法连接
2. nginx和php-fpm的链接被异常的断开

以下的分析通过nginx+php-fpm来进行分析,其他的工具也可以进行类似分析

php的配置文件:
http://php.net/max-execution-time
max_execution_time integer
这设置了脚本被解析器中止之前允许的最大执行时间,单位秒。 这有助于防止写得不好的脚本占尽服务器资源。 默认设置为 30。 从命令行运行 PHP 时,默认设置为 0。
最大执行时间不会影响系统调用和系统操作,更多细节查看:set_time_limit

http://php.net/manual/zh/function.set-time-limit.php

bool set_time_limit( int $seconds )
设置脚本可以运行的时间,单位是秒。如果超过了该设置,脚本会返回一个致命的错误。

set_time_limit()函数和配置指令max_execution_time只是影响脚本本身执行的时间,任何发生在如使用system()的系统调用,刘
操作,数据库操作等的脚本执行的最大时间是不包含在其中的。

php-fpm.conf文件:
request_terminate_timeout

3.实践测试

测试1:启动nginx,不启动php-fpm
现象:nginx服务器返回502
说明:nginx无法连接php-fpm,在达到nginx最大的超时时间的时候,nginx还没有获取到响应就会返回502

测试2:启动nginx,启动php-fpm

找不到您要找的信息?

创建工单
你觉得有用吗?
(238 次查看/0人发现它有帮助)

Top