Nginx+PHP-FPM intermittent blank page

Posted October 29, 2014 9k views

Hello, I been suffering with this problem for a few days on a new server, some times like 1 or 2 times a day the Home page of wordpress shows a blank page with a 500 error (only visible from Chrome console) and it stays like that for a couple of minutes where not even a hard refresh (ctrl+shift+R) seems to work, but eventually it comes back to normal. the only way to quickly fix it is to stop nginx, delete nginx cache at /var/cache/nginx/ and start nginx again.

The server is a CentOS 6.5, nginx/1.6.2, php 5.3.3 (php-fpm).
my site conf:
(maybe is a little tweaked from fail fix attempts but still functional 99% of the time)

The same error happens on a few selected pages but not in the post pages inside wordpress, so even when the homepage is blank the rest of the site works ok.

I use the same conf on other servers and websites but this is the only one causing me trouble, the main difference is this website has a lot more traffic (2k+ per hour).

I been looking around for days but nothing seems to solve it, now about the pages where the error occur this pages read a TXT file with a “cached version of the page” which is refreshed/rewritten every 2 minutes, this help us to load super fast the homepage (and some internal pages) which usually take a few seconds more to load without the “cache” text file.

Note: We use CloudFlare but the error shows even if I use my hosts file to connect directly to the server (no caching in the middle) my PC <–> Nginx

Any ideas or suggestions would be really helpful.

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.

Submit an Answer
2 answers

First of all, I’m not too familiar with Nginx as a reverse cache, but the configuration seems pretty straight forward.

Seems like you’re caching all requests for 8 minutes in fastcgi_cache_valid, which will cache a 500-error for that entire time. You’re also caching all 500-error responses for 2 seconds in Nginx. I’m a little unsure why you’re doing that, but I suspect it’s to let the server recover or something?

I bet you’re running out of PHP processes, which makes requests time out, giving you a 502 Bad Gateway or 500 Internal Server Error. This is then cached, and served up for the next 8 minutes according to fastcgi_cache_valid. Restarting and deleting the Nginx cache will naturally solve this.

Proposed solution, which will only cache requests that has returned 200 OK:

fastcgi_cache_valid any 8m;
fastcgi_cache_valid 200 8m;
  • Vegardx, if you put it that way it sounds obvious lol, I´m trying the change proposed and see how it works.

    About the 2s 500 cache, as you said -was an attempt to recover from the error, but obviously not very useful, but the fastcgicachevalid any 8m; makes much sense as for why the 500 error page stays for so long. I guess sometimes you need a fresh pair of eyes to look for the error right at your nose.

    I´ll try the new config and let you know. Thanks a lot for your help.

  • Vegardx, I wanted to thank you, the problem seems fixed thanks to your advice. I adjusted the resources on php-fpm and fixed the conf on Nginx, and the problem seems to be gone!

    Again thank you for your help.

please, you can share the solution, what are the files that you need change? ty. Excuse me my english.