0

I'm trying to setup my sites to run with fastcgi_cache and found it a bit problematic that it doesnt really refresh content when something new is added to my site/webshop.

So i stumbled upon the plugin nginx_helper, and it seemed to be everything i needed - but it requires the fastcgi_purge_cache module to be installed. I have now tried a couple of times on refresh AWS servers (obviously nginx and stuff installed aswell) - but i seem unable to get it to work.

Setup:
* AWS server
* Nginx / php-fpm / php 7
* Wordpress
* CentOS 7

I'm very new at server stuff, and i tried a couple of diffrent guides - but nothing seemed to workout in the end.
Im trying to install https://github.com/FRiCKLE/ , but im not quite sure how to do it correctly

2 Answers 2

0

I maintain a Copr repo with nginx rebuilt to include this specific module. You can enable it on CentOS 7 by installing the appropriate yum repo

[error-nginx]
name=Copr repo for nginx owned by error
baseurl=https://copr-be.cloud.fedoraproject.org/results/error/nginx/epel-7-$basearch/
type=rpm-md
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://copr-be.cloud.fedoraproject.org/results/error/nginx/pubkey.gpg
repo_gpgcheck=0
enabled=1
enabled_metadata=1

... or on Fedora with dnf copr enable error/nginx.

0

Nginx Helper, as you mentioned relies on a custom compile of Nginx, which can take some work to install and keep updated.

Cache Sniper for Nginx is a free WordPress plugin that can invalidate the FastCGI Cache, and works fine with the vanilla Nginx you get from doing a yum install.

Cache Sniper for Nginx can clear the entire cache:

cache sniper nginx clear entire cache

You can also clear the cache for specific pages, and automatically clear the page cache when it's updated or receives a comment.

Cache Sniper settings page

In your Nginx conf, you probably have fastcgi_cache configured similar to this:

fastcgi_cache_path /var/lib/nginx/webshop levels=1:2 keys_zone=WEBSHOP:1440m;
fastcgi_cache_key  "$scheme$request_method$host$request_uri";
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

server {
    set $no_cache 0;
    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
        set $no_cache 1;
    }
    if ($query_string != "") {
       set $no_cache 1;
    }
    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 $no_cache 1;
    }
    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
        set $no_cache 1;
    }
    location ~ \.php$ {  # this location block already exists, but you're adding lines to it
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_keep_conn on;
        fastcgi_index index.php;
        # The next few lines are new:
        fastcgi_cache WEBSHOP;
        fastcgi_cache_methods GET HEAD;
        fastcgi_cache_valid 200 100m;
        fastcgi_cache_bypass $no_cache;
        fastcgi_no_cache     $no_cache;
    }
    # ...
}

In order to use the plugin, you'll have to do a few things:

  1. Set the fastcgi_cache_key in your Nginx conf to: "$scheme$request_method$host$request_uri" (Nginx has to calculate the URL's hash the same way the plugin does.)

  2. Get the fastcgi_cache_path path (in this case: /var/lib/nginx/webshop) and paste it into the plugin settings. This is the Linux filesystem path where all the cached HTML is stored.

  3. Get the levels (in this case: 1:2) and also paste this into the plugin settings. This is just last few characters of the URL hash to organize cached pages into subfolders. For example: /var/lib/nginx/webshop/z/xy/qrstuvwxyz

(You can find the Cache Sniper for Nginx plugin settings under Tools)

1
  • 1
    Cache Sniper requires that PHP be able to write to nginx's cache. This is potentially extremely dangerous, as an attacker can then manipulate the cache without leaving much of a trace. Feb 14, 2018 at 22:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .