使用Nginx php-fpm和ubuntu的随机502网关错误 [英] random 502 gateway errors with nginx php-fpm and ubuntu

查看:90
本文介绍了使用Nginx php-fpm和ubuntu的随机502网关错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用nginx和php-fpm时出现随机502网关错误的问题.就我而言,我发现了一种情况,其中各种php.ini error_log设置和error_reporting级别都导致出现随机502网关错误.

I was having an issue with random 502 gateway errors using nginx and php-fpm. In my case I discovered a scenario where various php.ini error_log settings and error_reporting levels were causing the random 502 gateway errors to appear.

通过更改php.ini设置error_reporting和error_log,我能够使502网关错误消失-但更重要的是,我能够查看日志中真正的php错误并进行修复.

By changing the php.ini settings error_reporting and error_log I was able to make the 502 gateway errors disappear - but more importantly I was able to see what the real php errors were in the log and fix them.

主要问题是,如果将"error_reporting设置为显示通知," error_logging = On,则我需要确保将error_log设置为有效路径tat可以写入服务器.

The main issue was that if "error_reporting was set to display notices, "error_logging = On" then I needed make sure that error_log was set to a valid path tat was writable to the server.

// !!! 502 Gateway Error (unhappy server)
error_reporting = E_ALL & E_NOTICE
; error_log = php_errors.log (note this is commented)

// Happy Server, no 502 gateway error
error_reporting = E_ALL & E_NOTICE
error_log = /valid/log/path/and/permissions

// Happy Server, no 502 gateway error
error_reporting = E_CORE_ERROR
; error_log = php_errors.log (note this is commented)

请注意,实际错误是php通知...但是ngingx针对与未设置属性相关的php通知抛出502网关错误.

Note, the actual errors were php notices... however ngingx was throwing 502 gateway errors for php notices that were related to properties not being set.

还请注意,并不是在每个php通知中都触发了502个网关错误.

Also note, that 502 gateway errors were not being triggered on every php notice.

希望这可以节省一些挫败感!

Hope this saves someone some frustration!

推荐答案

Nginx中的502网关错误是由php-fpm没有足够的进程和/或超时引起的.记录只会告诉您问题是什么,而不是导致502错误的原因.

502 gateway errors in Nginx are caused by php-fpm not having enough process and/or timeouts. Logging only tells you what the issues are and are not the cause of 502 errors.

我在25台服务器上使用stunnel + haproxy + nginx + php-fpm. pfp-fpm中的默认值非常低,即使对于繁忙的服务器也是如此.配置fpm子进程的方式与使用Apache mod_php的方式几乎相同.

I use stunnel+haproxy+nginx+php-fpm on 25 servers. The defaults in pfp-fpm are very low, even for a moderately busy server. Configure the fpm child processes much the same way you would with apache mod_php.

我使用以下内容:

pm.max_children = 250
pm.start_servers = 20
pm.min_spare_servers =10
pm.max_spare_servers = 20
pm.max_requests = 1500

这是一台具有2GB内存的服务器.它每天可提供20-30GB的流量,没有502个

This is a server with 2GB ram. It serves 20-30GB traffic per day with no 502's

这篇关于使用Nginx php-fpm和ubuntu的随机502网关错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆