Website often has 502 errors

1. At present, there are many problems with lnmp one-click installation packages, which is 502 BadGateway. In most cases, the reason is that before installing php, some lib packages in the script may not be installed, resulting in php not being compiled and installed successfully. Solution: You can try to manually install it according to the script in the lnmp one-click installation package to see what caused the error.
2. In php.ini, the eaccelerator configuration item must be placed before the Zend Optimizer configuration, otherwise it may cause 502 BadGateway
3. 502 problems occur during installation and use, generally because the default php-cgi process is 5, 502 may be caused by insufficient phpcgi processes. You need to modify /usr/local/php/etc/php-fpm.conf to increase the max_children value appropriately.

Check how many php-cgi processes are opened on the server by command

ps -fe |grep "php"|grep -v "grep"|wc -l

 

Check how many php-cgi processes have been used to handle tcp requests

netstat -anop |grep"php"|grep -v "grep"|wc -l

 

Generally speaking, a server normally consumes about 20M of memory for each php-cgi. If I set this value to 80, it means that it will consume about 1600M of server memory.

Interpretation of related parameters :
pm.max_children : The number of php-fpm processes opened in static mode.
pm.start_servers : The number of starting php-fpm processes in dynamic mode.
pm.min_spare_servers : The minimum number of php-fpm processes in dynamic mode.
pm.max_spare_servers : The maximum number of php-fpm processes in dynamic mode.
Adjust these values ​​for my server situation :
pm.max_children = 20
pm.start_servers = 12
pm.min_spare_servers = 5
pm.max_spare_servers = 20

4.php执行超时,修改/usr/local/php/etc/php.ini 将max_execution_time改为300
5.磁盘空间不足,如mysql日志占用大量空间
6.查看php-cgi进程是否在运行
7.Nginx 502 BadGateway的含义是请求的PHP-CGI已经执行,但是由于某种原因(一般是读取资源的问题)没有执行完毕而导致PHP-CGI进程终止,一般来说Nginx 502Bad Gateway和php-fpm.conf的设置有关。php-fpm.conf有两个至关重要的参数,一个是max_children,另一个是request_terminate_timeout,但是这个值不是通用的,而是需要自己计算的。在安装好使用过程中出现502问题,一般是因为默认php-cgi进程是5个,可能因为phpcgi进程不够用而造成502,需要修改/usr/local/php/etc/php-fpm.conf将其中的max_children值适当增加。

 

在配置nginx.conf 的时候,有一项是指定错误日志的,默认情况下你不指定也没有关系,因为nginx很少有错误日志记录的。但有时出现问题时,是有必要记录一下错误日志的,方便我们排查问题。
error_log 级别分为 debug, info, notice, warn, error, crit  默认为crit, 该级别在日志名后边定义格式如下:
error_log  /your/path/error.log crit;  
crit 记录的日志最少,而debug记录的日志最多。如果你的nginx遇到一些问题,比如502比较频繁出现,但是看默认的error_log并没有看到有意义的信息,那么就可以调一下错误日志的级别,当你调成error级别时,错误日志记录的内容会更加丰富。

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326496419&siteId=291194637