Must I install a plugin for Nginx object caching? [closed]

I do not know plugin to control FastCGI cache in nginx. However, there are a set of nginx rules to use the WP Super Cache cache directly.

Let us think – what is going on when site page is accessed?

  1. nginx accepts request and sees that index.php is needed
  2. nginx starts php-fpm (what is not fast at all)
  3. WordPress starts to work
  4. At the beginning, WP Super Cache plugin encounters and slips already saved .html instead of infinitely long (in these timing terms) page generation

None of that is bad, but: we need to start php-fpm, and then to execute some php code, to respond with saved .html.

There is a solution how to proceed without php at all. Let us do rewrite on nginx at once.

Edit /etc/nginx/conf.d/servers.conf – and after index index.php; line insert:

include snippets/wp-supercache.conf;

Create folder /etc/nginx/snippets and file wp-supercache.conf in it with the following content:

rewrite ^([^.]*[^/])$ $1/ permanent;

set $cache_uri $request_uri;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
    set $cache_uri 'null cache';
}
if ($query_string != "") {
    set $cache_uri 'null cache';
}

# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php
                      |wp-.*.php|/feed/|index.php|wp-comments-popup.php
                      |wp-links-opml.php|wp-locations.php |sitemap(_index)?.xml
                      |[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {

    set $cache_uri 'null cache';
}

# Don't use the cache for logged-in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+
                     |wp-postpass|wordpress_logged_in") {
    set $cache_uri 'null cache';
}

# Set the cache file
set $cachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index.html";
set $gzipcachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index.html.gz";
if ($https ~* "on") {
    set $cachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index-https.html";
    set $gzipcachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index.html.gz";
}

# Add cache file debug info as header
#add_header X-Cache-File $cachefile;

# Try in the following order: (1) gzipped cachefile, (2) cachefile, (3) normal url, (4) php
location / {
    try_files $gzipcachefile $cachefile $uri $uri/ /index.php;
}

Executing this instructions, nginx looks by itself, if there is .html available (or compressed .html.gz) in WP Super Cache plugin folders, and if .html exists, takes it without starting any php-fpm at all.

For more details, please read my article https://kagg.eu/en/10000-clients-second-wordpress/. Section “rewrite in nginx” describes nginx settings aimed to work together with WP Super Cache plugin.

It is a bit different than FastCGI cache in your question but works well.