Install and configure wordpress caching with WP Super Cache in nginx.

share on:
install wp super cache in nginx

Website loading Speed is one of the most important factor that search engines considers for ranking. If you are using Nginx then you can configure inbuilt support of FastCGI cache to speed up your WordPress performance.

There are many caching plugins available for wordpress, that we can use to improve your website load time. For e.g W3 total cache, Comet cache plugin or WP Super Cache.

All of these plugins are great and should be considered depending on your needs.

Here we will configure WP Super Cache to speed up our website.

 

Why use W3 Super Cache

W3 super cache speeds up your website performance by creating static pages of your WordPress site and serving them instead of using Expensive PHP scripts to serve Pages.

Benefits of serving static pages is that it reduces page number of PHP calls and thus increases website performance.

 

Prerequisites.

You should and must use only one caching plugin at a time and never should use two caching plugins (for e.g WP Super Cache and w3 total cache) together.

Again never use two caching plugins together.

If you already have any caching plugin installed then you should deactivate that plugin and delete it properly before installing WP Super Cache plugin.

You can follow this post to completely uninstall W3 Total Cache Plugin.

 

Install W3 Super cache plugin.

Here is an Easy way to install this plugin.

Go to your WordPress dashboard > Plugins > Add New. Search for “WP Super Cache” and install.

For more details on installing WordPress plugins via Dashboard or FTP use this.

 

Configuring WP Super Cache

Go to Settings > WP Super Cache.

You will be taken to WP Super Cache Settings page.
There are few tabs with various options that we will configure.

 

Easy

To enable cache, turn Caching on under the Easy tab and press update status button.

install wp super cache in nginx

 

Advanced 

To further improve your site’s performance we will configure Advanced options for WP Super Cache.

install wp super cache in nginx

 

For those who are using Nginx web server, you should select PHP for better performance.

For Apache web server use mod_rewrite and then follow the instructions.

In Miscellaneous, Click Compress pages so they’re served more quickly to visitors. (Recommended) to serve cached files as compressed files. Compressed files are smaller in size and hence quick to download.

Then click Update Status to apply changes.

Scroll down to configure the next section.

 

Expiry Time & Garbage Collection

Set Cache Timeout and Scheduler as shown in the image.

install wp super cache in nginx

 

Accepted Filenames & Rejected URIs

Ignore all.

 

Rejected User Agents

ignore all.

 

Lock Down: Disabled

ignore all.

 

Directly Cached Files

ignore all.

Now move on to the next tab.

 

CDN

Click on the CDN tab to setup CDN in WP Super Cache.

install wp super cache in nginx

 

Check Enable CDN Support box.

Enter your off-site URL, which will be the url of your pullzone. For e.g, http://static.debyum.com

At Last check the box for Skip https URLs to avoid “mixed content” errors.

 

CONTENTS

Here you will the list of Super Cached Files created by WP Super cache. Nothing to configure here.

install wp super cache in nginx

Here is sample of Super Cached Files create by WP Super Cache for DebYum.

 

Preload

The important settings for Preload.

install wp super cache in nginx

 

Next one is for debugging.

 

DEBUG

If you are having any problems with the working of WP Super Cache then you can use this option to debug the error.

install wp super cache in nginx

 

Here’s  example of, what Debugging will look like if enabled, to check the working of WP Super Cache.

View the page source of your Blog front page and scroll down to the bottom, you will see something like this.

wp-super-cache-debug-testing

 

 

Integrate WP Super Cache with NGINX.

To make WP Super Cache work with Nginx, you need to modify you nginx.conf file.

Insert this code into your nginx.conf file.

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";

# Server the SuperCache file for HTTPS connections.
 if ($https ~* "on") {
 set $cachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index-https.html";
 }

# Use cached or actual file if it exists, otherwise pass request to WordPress
 location / {
 try_files $cachefile $uri $uri/ /index.php;
 }

 

 

Here’s a sample config file.

 

install wp super cache in nginx

 

Save this settings and reload the Nginx server.

nginx -s reload

 

 

Test the Working of WP Super Cache.

To test the working of WP Super Cache, go to WP Super Cache Settings > EASYCache Tester > Test Cache.

install wp super cache in nginx

 

click on the Test Cache. WP Super Cache compares the time stamps of pages via fetching them twice.

If the both time stamps match then this means that caching is working on your site now.

Now your WP Super Cache is Up and running properly.

 

Reference:  A very useful post on how to improve Nginx performance  9 Tips for Improving WordPress Performance.

 

Conclusion

WP super cache is a great plugin to improve your site performance and it does not require much effort ro technical knowledge to configure it. It is so very easy to use and works very well.

I hope this guide will help you in setting up WP Super Cache on your WordPress website/blog. Still if I have missed anything please update us through comment box. I will keep updating the same based on feedback’s received. Thanks and Good Day.

share on:
engy

engy

Hello there, My name is Rishi Guleria and I work as a Linux system administrator. I have created this blog to share what I have learned so far and to learn new things. Good Day. :)

Leave a Response

share on: