How to purge the ngx_pagespeed Module's Cache

I would like to share a quick tip for all of the system admins or web developers out there. This tip is a genuinely essential component in the toolkit for anyone who uses Apache's ngx-pagespeed module or really anyone who needs to purge an Nginx reverse proxy cache.

I use prefer to use the CentminMod script for my WordPress virtual private servers which is a bash script that automates the installation, configuration, and optimization of a LEMP web server stack, and is an alternative to solutions like Cpanel or Plesk. It can also be used for tiered architectures on a more advanced level. It runs on Linux distribution CentOS versions 6 or 7 and the essential elements are Nginx web server, MariaDB database, and PHP-FPM for web sites and applications. The script has quite a bit more functionality that can be covered in a single blog post so I will be covering many of its features in future posts.

I am actually choosing this topic to lead of the CentminMod articles due to the fact that pagespeed module for Nginx was a topic that I was extremely interested in when I began my tech journey into WordPress at the beginning of my web development career. The great thing about CentminMod is that it automates the installation from source of Nginx and includes an easy way to compile your server with Pagespeed module using a simple custom configuration file that sets flags for customizing Nginx built from source and in this way is very easy to tweak for performance and functionality. On top of this the script also automates the configuration of vhost files, caching, and the installation of WordPress web sites including free SSL certificates via the LetsEncrypt certificate authority.

The quickest an surest way I have found to purge the Nginx Pagespeed Module's cache is to simply remove the files in the cache which if you are using the CentminMod script can be accomplished by simply deleting the cache files is accomplished by running the following rm command.

$ sudo rm -rf /var/ngx_pagespeed_cache/*

This should be then followed by restarting Nginx by running

$ sudo systemctl restart nginx

Please keep in mind that the location of your cache files may very well be in another location so make sure that you know the path to your cache files before running the rm command.