Question

502 Bad Gateway Randomly Ocurring

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.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

jsamuel, where to find “PHP-FPM pool’s error log and slow log as well the global FPM log”?

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 :)