502 bad gateway 可能的错误原因

1、PHP程序的执行时间超过了Nginx的等待时间,可以适当增加nginx.conf配置文件中FastCGI的timeout时间

#http代码段中增加
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

2、header 头信息过大

3、FastCGI进程数不够用增大 php-fpm.conf 中的 max_children max_requests 值

4、各种超时

nginx 中的  fastcgi_connect_timeout 300; fastcgi_send_timeout 300 :fastcgi_read_timeout 300; keepalive_timeout ; 
php-fpm中的 request_terminate_timeout
php.ini中的 max_execution_time

5、php-fpm.conf  max_requests  每个children最多处理多少个请求后便会被关闭 

在大量处理请求下,如果该值设置过小会导致children频繁的自杀和建立而浪费 大量时间,若所有的children差不多都在这个时候自杀,则重建前将没有children响应请求,于是出现502

原文地址:https://www.cnblogs.com/siqi/p/3658771.html