WordPress, NGINX, Cache, Plesk, and why is my TTFB so high

To put it mildly, tuning a server is complicated, even for incredibly common setups and out-of-the-box solutions. In the end you’ll hear mostly that you need to install this, or that, plugin. You do, but you don’t. In reality most systems seem to have moved to an NGINX setup and all of the .htaccess rule tricks in the world do not work if you’re bypassing apache to serve the files directly.

My preferred server environment is a CentOS server running Plesk. I choose this system because it has a lot of convenient features built to enable me to produce, copy, test, backup, and administer multiple wordpress installations quickly, quietly, and without much hassle. The only hassle was learning how to work with FPM served by NGINX as opposed to just Apache the way we all did in the 2010. In the end, it’s faster, but there are pitfalls along the way.

First, Lets make sure it loads.

Diving in to your first installation on a plesk server for wordpress, you’ll usually encounter an issue whereby the site works, but the entire site seems to only load the home page. Do a little digging and you’ll find this rule as a godsend:

if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) {
set $test "${test}C";
}
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;
}

Source: https://support.plesk.com/hc/en-us/articles/213912945-After-switching-a-WordPress-website-to-FPM-served-by-nginx-in-Plesk-it-fails-to-load-with-404-Not-Found-on-all-pages-except-start-page?page=2

Do a little more digging, and you’ll likely want to run this setup instead:

rewrite !.(js|ico|gif|jpg|png|css|pdf|mov|mp3|eot|svg|ttf|woff|otf|txt|swf)$ /index.php break;
rewrite /wp-admin/$ /wp-admin/index.php break;
rewrite /$ /index.php break;

Source: https://www.websavers.org/how-to-speed-up-wordpress/

Of course you should also make sure your site hasn’t been hacked.

OK it loads, my plugins are working, but the time is slow. What do I install?

Here’s where the fun starts, You’re going to jump into lighthouse and ask why, oh why, oh why is this brand new server running an empty wordpress site and why is my TTFB so high? The answers are entirely in the fact that google expects more out of you, and the expectations are focussed on using solutions that don’t operate the way wordpress does, so you’re gonna make some changes.

A couple notes about plugins

My recommendations are based on my experience working on live sites and testing them. Your selection of plugins for SEO, minification, concatenation, etc. are fine. There are a lot of ways to get there.

My Recommended set

  • Yoast SEO <– Get found
  • Autoptimize OR MMR <– Cut down on your requests
  • Imagify or Shortpixel <– Next Gen Formats without thinking about it
  • jQuery Updater <– Google will doc you for ages old jquery problems in the wordpress core, it’s been a problem for a while.
  • Elbow grease on the server side.

I’d like you to note that I’m not using any of the caching plugins you’ll read so much about. They’re built on serving things through apache, you’re not going to let things get that far with this setup because NGINX is going to do the work for you. Also keep in mind, your site may vary. I do not run this set on every site.

Great, You’ve gotten Started

You should be in better shape, but really there’s always new information and updates on wordpress. WP 5.5 recently launched and has some under the hood improvements that have drastically changed some optimizations on wordpress. If you get stuck, drop me a line and I can help.