Sukh
By:
Sukh

502 Bad Gateway Randomly Ocurring

August 6, 2015 17.6k views
Nginx PHP Caching

Hi

I have a droplog setup on CentOS7 running the latest version of Nginx and PHP-FPM and a couple of modules like mbstrings, gd and common. I have also enabled OPCache and APCU.

Whilst browsing my website I am getting random 502 Bad Gateway on different pages. Refreshing the page 1-4 times loads the page. Restarting PHP-FPM allows me to browse about 7-8 pages before the issue happens afterwhich every 3-4 different pages later this error occurs on it.

I have looked at the nginx log

2015/08/06 10:13:10 [error] 10996#10996: *1042 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 90.216.134.197, server: www.s-heer.co.uk, request: "GET /discography/a/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.s-heer.co.uk", referrer: "http://www.s-heer.co.uk/discography/"
2015/08/06 10:13:13 [error] 10996#10996: *1042 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 90.216.134.197, server: www.s-heer.co.uk, request: "GET /discography/a/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.s-heer.co.uk", referrer: "http://www.s-heer.co.uk/discography/"
2015/08/06 10:23:59 [error] 10996#10996: *1061 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 90.216.134.197, server: www.s-heer.co.uk, request: "GET /discography/f/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.s-heer.co.uk", referrer: "http://www.s-heer.co.uk/discography/e/"

Not really sure how to proceed or what to do to fix this. The only difference between my DO drop and where my current site is hosted is DO drop I have added APCU. My other host where my site currently is does not have this issue. I cant migrate over to DO until this is resolved as it would result in to many 502 errors.

3 Answers

Hi, I suggest checking the PHP-FPM pool's error log and slow log as well the global FPM log. One of these log files is very likely to tell you more about the problem.

If none of those log files tell you anything, you might want to check syslog for "out of memory" errors just in case your server is running out of memory while handling requests and so the kernel is killing PHP processes in the middle of a request.

Hi

Thanks for the reply. Seems memory was running low once APCU was caching. I followed steps to add a SWAP file and all seems fine now :)

jsamuel, where to find "PHP-FPM pool's error log and slow log as well the global FPM log"?

Have another answer? Share your knowledge.