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 lev
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.
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.
I use the following:
pm.max_children = 250
pm.start_servers = 20
pm.min_spare_servers =10
pm.max_spare_servers = 20
pm.max_requests = 1500
This is a server with 2GB ram. It serves 20-30GB traffic per day with no 502's
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! =)
I have a similar problem that resolved by disabling PHP warnings, however, I think the problem has something to do with NGINX configuration of the buffers which the error logging uses. The error only triggers after a certain number of warning messages are queued, and seems to be quite predictably repeatable; but I can't figure out what settings are involved so have shut off the warnings until I can resolve the settings that are broken.
If above steps don't help you solve your issue, check if you have eaccelerator 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 accellerator fails in certain situations in combination with php-fpm.