Alex Rivera | Logout

random 502 gateway errors with nginx php-fpm and ubuntu

Asked 2012-05-10T19:23:16.677
15

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.

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.

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)

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.

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

Hope this saves someone some frustration!

Edit
Report

2 Answers

0

I've run into this on windows machines running iis and php in fastCGI mode so it isn't just a nix problem.

The culprit was php logging as well. You don't have to set it to a static directory though if you grant proper permissions it can write to the same directory that the script resides in. (Can be very helpful if you have a large and complicated site)

My server is setup this way and I just added a rule to not serve the error logs to the public.

To sum it up, CHECK PERMISSIONS! =)

answered 2012-06-22T18:23:48.340
0

If the above steps don't help you solve your issue, check if you have accelerator enabled.

Disable it globally by disabling the load .so entry in either your php.ini or php.d/eaccelerator.ini

All problems are gone. Seems like the accelerator fails in certain situations in combination with php-fpm.

answered 2013-07-21T11:30:02.820

Your Answer