How to configure file based cache for WordPress websites

Hi,
Since Cleavr is powered with NGINX we need to add some rewrites for WordPress Cache plugins.

Is there any information available for using WP Rocket or WP Super Cache?
I’m looking for examples serve the cached files just like you do with mod_rewrite (Apache).
Besides this, is there some information that describes how to customize your NGINX configuration for a single website?

Hi @finalwebsites, welcome to the Cleavr forum!

Here is a resource WP Rocket provides with some tips working with NGINX https://docs.wp-rocket.me/article/37-nginx-configuration-for-wp-rocket and includes a link to a project that looks to deep dive into config settings even more - https://github.com/SatelliteWP/rocket-nginx.

For modifying NGINX settings in Cleavr. There is currently server level configs you can add via server > services > NGINX settings (wrench icon). The same is available for PHP.

If you choose to use FastCGI, you can enable that for a site and modify settings from Cleavr.

For modifying NGINX settings at the site level - this is something we’re planning on adding very soon. But, in the mean time, can be modified on server via SSH or SFTP.

For example, a common task might be to tweak cache settings for images -

  1. SSH into server (I like SSH and console commands as it feels quicker, but file locations will be same for SFTP)
  2. Navigate to NGINX configs - cd /etc/nginx/sites-available
  3. Then you can view the current sites set up via command ls -alt
  4. To edit a site’s settings using vim, vim <sitename>

Then you can edit accordingly -

location ~* \.(gif|jpg|jpeg|png|css|js|svg)$ {
        expires max;
        access_log off;
    }

The above is just a generic example to show you where the site level configs are.

I hope that helps!


Here are some guides on accessing Cleavr managed servers that may be helpful -

Hi Adam,
thanks for the information. This is actually not what I’m looking for. File based cache is an important feature for most WordPress sites. If you host your website on a server which is based on NGYNX, it’s not a standard configuration.
Example configurations are very helpful here.

I know this information enough to avoid it. Installing some script to create your NGINX config file? Sounds quick and dirty to me.

My post here is not to “push” a new feature into Cleavr, but a suggestion to create a better documentation than others have. I’m sure many people avoid using NGYNX based servers because their (cache) plugins doesn’t work very well.

Hi finalwebsites,

I’m curious how you solved this issue, also related to dynamic sites (such as sites using WooCommerce) that also need updated configs. Since you’re also hosting a lot of sites with Cleavr, I’m curious to your experiences and your setup.

1 Like

Hi Michiel,
You’re right I’m hosting many websites with Cleavr :slight_smile:
File based caching with Nginx is a bit different from Apache.
Right now I’m using Nginx Cache for most of the sites. If you compare the tweaks from Cleavr with the .htaccess directives from WP Super Cache, you can see that both are almost the same. It’s only the WooCommerce that’s missing. You need to add some Nginx directives for the pages like cart, checkout and maybe some cookies. At the end you exclude most of all pages :slight_smile:

Last year I had a discussion with a developer from WP Rocket about why their plugin doesn’t create a file based cache anymore (the create the files, but they access them via PHP).
That was because the so many plugins need dynamic data, for example a cookie notice.

To make this short, if you like to use a WP cache plugin, just use the PHP based version.

I really like to use Cleavr, mostly for simple WP sites. Like I said before I’m using Nginx Cache for most of them. Anything else is mostly the default from Cleavr.

3 Likes

Haha yes, I read it (hosting the many sites) somewhere. As I’m investigating some platforms for some serious use (Cleavrs performance is really good) I want to know how people use it :).

Thanks anyway for your reply! It’s clear now how it works. And how do you deal with security?

By the way, for WP-Rocket, the script that Adam pasted seems to work pretty well for serving WP Rockets cache directly over NGINX.

Ninjafirewall on website level. There is also a way to use fail2ban with Ninjafirewall.

Yes, the WP rocket team gives the advice to use that script too, but read my previous comment about. I think it makes sense :slight_smile:

Today I tried these steps like described here: GitHub - SatelliteWP/rocket-nginx: Rocket-Nginx is a Nginx configuration that makes WP-Rocket even faster by serving static pages directly without loading WordPress or PHP.
It works and I can see that the cached version is loading.
The installation process looks like a workaround, but it’s just a simple script to install the right files/vars for your server. I like it :slight_smile:

It’s time to check if this is fully works for WooCommerce sites!

1 Like