• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

GridPane

  • How it Works
    • Creating Servers
    • Creating Websites
  • Use Cases
  • Pricing
  • Knowledge Base
  • More
    • FAQ
    • Apollo
    • Comparisons
    • Updates
  • Login
  • Free Trial
GridPane >Knowledge Base > Exclude a page from server caching

Exclude a page from server caching

Steve B
Updated on 5th August 2020

3 min read

If you’re building projects for your clients, or you’re managing a website that has some complex functionality, you may find that you need a page to be excluded from the cache for it to work correctly.

This article will walk you through how to set this up with GridPane’s server caching options.

Before we begin, be sure to confirm which cache type you’re using inside of your websites customizer by heading to you Sites page inside your GridPane account and clicking on your sites domain name.

Step 1: Log into server as root

Use your favorite SSH client and connect to your server IP as root. If this is your first time connecting to one of your servers, please see the following articles to get started:

Generate your SSH Key:

Generate SSH Key on Mac

Generate SSH Key on Windows with Putty

Generate SSH Key on Windows with Windows Subsystem for Linux

Generate SSH Key on Windows with Windows CMD/PowerShell

Add your SSH Key to GridPane:

Add default SSH Keys

Add/Remove an SSH Key to/from an Active GridPane Server

Connect to your server:

Connect to a GridPane server by SSH as Root user.

Step 2: Exclude your page/s

Now inside your server we need to add our page exclusions. Be sure only to use correct command below for the type of page caching you’re using. Adding our exclusion to the wrong caching method will have no effect.

Redis: If you’re using Redis page caching, enter the following and hit enter (replacing site.url with your domain name):

nano /var/www/site.url/nginx/custom-skip-redis-cache-context.conf

FastCGI: If you’re using FastCGI page caching,enter the following and hit enter (replacing site.url with your domain name):

nano /var/www/site.url/nginx/custom-skip-fcgi-cache-context.conf

Then copy the below information and paste inside your SSH client. On most machines, this will be a right-click with your mouse, not a CTRL + V.

if ($request_uri ~* "(/examplepage/)") {
 set $skip_cache 1;
 set $skip_reason "${skip_reason}-request_uri";
}

If all worked correct your screen should look like this:

mceclip0.png

Now just hit CTRL + X on your keyboard, and it will ask if you want to save, click Y to save.

Exclude Multiple Pages

You can exclude multiple pages from the cache like this:

if ($request_uri ~* "(/examplepage/|/another-page/|third-page/)") {
 set $skip_cache 1;
 set $skip_reason "${skip_reason}-request_uri";
}

Wildcard Exclusions

If you want to exclude a parent page plus all child pages, or an entire CPT (or whatever your use case), you can create a wildcard exclude like this:

if ($request_uri ~* "(/parent-page.*)") {
 set $skip_cache 1;
 set $skip_reason "${skip_reason}-request_uri";
}

Exclude with Cookies

This is more advanced, but useful for developers who have specific use cases where adding each page individually / having to update this regularly could be better handled by setting cookies on specific pages instead.

Follow the same steps as above, but instead of adding a page specific exclusion, use the following code block to add a cookie exclusion:

if ($http_cookie ~* "your_cookie_name") {
set $skip_cache 1;
set $skip_reason "${skip_reason}-your_cookie";
}

Step 3: Test your nginx (important)

You’ll want to run an “nginx -t” on the command line.

nginx -t

This will test your configs, and if all is well, it will show the below message. If it shows any failures, or any message other than what is below, do not proceed to step 4:

mceclip1.png

Step 4: Reload nginx configuration

Remember, if you didn’t have a successful test above, do not proceed. Finally, reload your nginx config by running:

gp ngx reload

Primary Sidebar

Search the Knowledge Base

  • Provisioning Servers
  • Managing Servers
  • Managing Websites
  • SSL Certificates
  • Server Caching
  • Migrating to GridPane
  • Plugins / Services
  • Security
  • Performance
  • SMTP / Email
  • FAQ
  • Policies

Footer

Quick Links
  • Documentation
  • Status
  • Roadmap
  • Comparisons
  • Updates
  • Facebook Group
Connect With Us
  • (619) 4-SERVER
  • info@gridpane.com
Facebook-f
Twitter
Youtube

GridPane is the world’s first hosting control panel purpose-built for Serious WordPress Practitioners

© Copyright 2017-2021 – GridPane – Run WordPress the Right Way

Terms of Service – Privacy Policy – GDPR
Built with ❤ by S Bell
  • How it Works
    • Creating Servers
    • Creating Websites
  • Use Cases
  • Pricing
  • Knowledge Base
  • More
    • FAQ
    • Apollo
    • Comparisons
    • Updates
  • Login
  • Free Trial