How to flush nginx pagespeed cache on a Ubuntu server?

How to flush nginx pagespeed cache on a Ubuntu server?

What is nginx pagespeed?

It is actually a third party dynamic module for nginx, which can be compiled into nginx server. It is provided by Google PageSpeed, a suite of tools for measuring and optimizing the performance of your website. 


Flushing pagespeed cache

After compiling nginx pagespeed module, the pagespeed cache is not getting cleared after running the cache flush command.
To flush nginx pagespeed cache you must run a simple touch command against the directory specified as FileCachePath in your nginx configuration file for the server.  Touch command is actually used to create empty files in linux. 
  1. sudo touch /var/ngx_pagespeed_cache/cache.flush 

This will create an empty file in the directory with path /var/ngx_pagespeed_cache. These files are actually ignored from the Pagespeed cache until they are finally deleted. In short, after running this touch command, the previous cache files already stored gets invalidated.

Alert : The steps down below are not necessary, especially for live sites, as visitor might see a 500 error. Although, if you still want to remove cache files forcefully, after they are invalidated, run the rm (used to delete files in linux) command.

Remove the files from /var/ngx_pagespeed_cache directory.
  1. sudo rm -rf /var/ngx_pagespeed_cache/*

After that, restart Nginx to apply changes :

  1. sudo service nginx restart


You can now check manually. The cache files will start to generate in the /var/ngx_pagespeed_cache directory after restarting nginx webserver.

    • Related Articles

    • How to Connect to an SSH Server from Windows, macOS, or Linux

      An SSH client allows you to connect to a remote computer running an SSH server. 1. Windows The most popular and widely recommended solution for connecting to SSH servers is an open source, third-party application called PuTTY. But now with windows 10 ...
    • Compiling code and deploying static view files in magento2

      Code compilation To compile the code in magento2, we use setup:di:compile command which performs the following tasks : Application code generation – for factories, proxies Interceptor generation – improve code generation of interceptors Interception ...
    • How to configure base URLs for a Magento 2 website?

      In this article, we are going to change the base URLs of a Magento 2 website, using the swiss army knife for Magento developers, sysadmins and devops i.e. n98-magerun2. Base URLs can be also changed from the Magento Site backend as well as from the ...
    • How to configure base URLs for a Magento 1 website?

      In this article, we are going to change the base URLs of a Magento 1 website, using the swiss army knife for Magento developers, sysadmins and devops i.e. n98-magerun. Base URLs can be also changed from the Magento Site backend as well as from the ...
    • [How to] Reset VirtualMin ftp password

      Reset VirtualMin ftp password Login to the VirtualMin dashboard: on https://server_ip_or_dns_name:10000 Login using the root login. From the VirtualMin Dash drop down on left hand side, select the domain. Edit Virtual Server > Configurable settings ...