How to Fix and Avoid WordPress Blank Page on NGINX

On Windows OS – the most popular opearting system for personal users, we have Blue Screen of Death as most common error screen. And with Nginx – the one of most popular web server softwares, we have White/Blank Screen of Death too. Unlike Windows Error Page, you won’t find useful information when facing with that problem because the it’s set hide from public by default, you need research the nginx and php logs to solve it.
If you don’t have a lot of experience with nginx, you will confusing with this common error like 403 Forbidden problem. In this post, I will explain about the solution to fix and avoid White/Blank Page when running WordPress on Nginx.

Environment Details

  • Arch Linux (also works on Ubuntu, Centos, Debian, Fedora …
  • Nginx
  • PHP-FPM
  • FastCGI-Cache
  • WordPress

I have noticed the WordPress sometimes was showing blank pages after moved on Digital Ocean. I’ve just spent a while debugging this, was tricky’er than I thought. PHP has no error_log by default. My Nginx error log also displayed no errors relating to PHP. This is probably a hopeless case, I tried everything: setting permissions again, monitoring the logs for errors, configuring again Nginx and PPH-FPM. Everything checked, the status pages, the ping stubs, the logs still showed no errors… so this was quite the mystery.
Because I setup my nginx server with block of configuration in separated conf files. To debug, I’ve tried to remove them until the problem has solved. Then I found the problem is FastCGI-Cache. It’s the cause in most cases of WordPress white/blank page problems on Nginx.
Here are some solution to solve each individual case.

Nginx Serving WordPress Blank Page

Look into the /etc/nginx/ folder, you’ll found two fastcgi files: fastcgi.conf and fastcgi_params. By default the Nginx source does not define SCRIPT_FILENAME in the fastcgi_params file and the fastcgi.conf file was missing the definition of PATH_TRANSLATED.
Here’s what I eventually went for that worked.

location ~ \.php$ {

    fastcgi_split_path_info ^(.+\.php)(/.+) $;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Seems like a really silly thing but DON’T COPY & PASTE THIS, just add them individual for testing until it’s solved.
Hope this helps.

White/Blank WordPress Homepage, but other sites/urls working

For several weeks before, I’ve received some emails of my audience about the white/blank homepage when visit directly, it’s still working if visit other sites or back to homepage from internal links. It works when it’s come from non www url too (I setup main domain with www prefix).
I’ve researched the logs then found white/blank homepage is returning a “200 OK” HTTP status code. That’s mean it’s being passed to PHP-FPM corectly then cached but don’t return a body. That’s why the homepage was caching and serving as blank pages.
Like I mentioned before, it’s occured only when the visitor go to https://www.narga.net/ directly. If they go to the homepage from other sites or type only narga.net without www prefix, it still works like the normal.
Yes, FastCGI-Cache is the cause of this problem. And the method of visitors to visit NARGA will considering the problem will happen or not.
Here’s the configuration line to solve it:

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+) $;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_cache_key $host$request_method$request_uri;
}

Fix for Yoast XML Sitemap Blank Issue

This problem hasn’t occured with us, I discovered it when I submit a new website to Google Search Console (former as Google Webmaster Central).
If you’re using W3 Total Cache plugins, make sure the setting “Do not process 404 errors for static objects with WordPress” is turned on then add the following exception into 404 error exception list:

	([a-z0-9_\-]+)?sitemap(_index)?(-)?([0-9]*)?\.(xml(\.gz)?|xsl)$

It needs to exclude in Minify setting too.
To solve this problem with W3 Total Cache, just Clear All The Caches are not enough, you must reload the nginx service to clean old cache then create new caches.

Conclusion

These are most common cause of WordPress Blank Pages on Nginx error. These solution allow my server working flawlessly but may be it breaks your server. DONT’T COPY & PASTE, just test it carefully.
Hope it helps.

Must Read:

2 thoughts on “How to Fix and Avoid WordPress Blank Page on NGINX”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.