How to exclude pages from Redis?


How are you guys exclude certain pages or even directories from Redis cache? I’m using Redis cache but need some pages to be excluded from being cached? What is the proper syntax/rules for Nginx?

Thank you.


You’ll need to edit e.g. redis.conf in /etc/nginx/common/ (there is more than one redis related file, so also look at your sites main conf file to see which is being included). You’ll see there are rules in there already to not cache certain directories/files.

Bear in mind the include files in /common/ are used server wide, so you may want to create a copied custom version for this domain only. You will also need to be careful with ee upgrades as you’ll no longer be using the standard setup.

I’m sorry if my question wasn’t clear but I know how to include custom rules, I was asking which rules do I need to add to skip caching of certain pages. Meaning Nginx exact syntax/rules.

But thank you for trying to help anyway.

You’ll see there are rules in there already to not cache certain directories/files.

Just follow what is already there :slight_smile:

What is already there may not be my cases there therefore I want someone to provide an example. E.g. the following rules:

# Don't cache URL containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|/feed/|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
  set $skip_cache 1;


# Skip cache on WooCommerce pages
if ($request_uri ~* "/cart.*|/my-account.*|/checkout.*|/addons.*") {
   set $skip_cache 1;

Can I use either of them or only first example, if, say, I want to skip cache for the following directories:

/test /test/sub-directory/sub-sub-directory

Should I use both /test/ and /test so both urls are skipped or only one is enough?

Thank you.

?? They are the same thing - an if statement with a pattern match, to set a variable that is used later to skip caching.

Just copy/paste and amend, e.g.

if ($request_uri ~* "(/test/|/test/sub-directory/sub-sub-directory/)") {
  set $skip_cache 1;

But note what I said above. I suggest you:

  1. copy the relevant redis.conf file to /var/www/
  2. add your new rules into this site specific copy of the file
  3. comment out the include of whichever redis.conf is being used in your sites main conf

It depends what behaviour you want - they are different URLs, /test could be a page.

I figured it out, thank you