Today I was working on a particular dedicated cluster that was an image http cluster, it was designed to serve massive images from a high level traffic website. The images are balanced across the three nodes, with a basic LEMP stack.
Nginx was compiled manually with mod_pagespeed (known as ngx_pagespeed). Everything on the servers was working fine, however there is one thing I’ve seen a couple of times on ngx_pagespeed powered servers, an is the fact that the pagespeed cache is not getting cleared ok after running the flushing command.
Flush Nginx PageSpeed Cache Server-Side
According to the official docs, to flush nginx pagespeed cache you must run a simple touch command against the directory specified as FileCachePath. For example:
In my case FileCachePath was
As this is a cluster environment, I had to clear the nginx pagespeed cache on the three servers.
However, even after restarting Nginx, I’ve found there are still many files created inside /var/ngx_pagespeed_cache/ directory, those files were not deleted at all.
That was the time when I read that on pagespeed docs that the files are actually not deleted by running the touch command shown before, they are just ignored from the Pagespeed cache until they are finally deleted (this is determined by FileCacheCleanIntervalMs variable).
However, the problem was that they were actually not ignored at all, and I couldn’t wait until PageSpeed hit the FileCacheCleanIntervalMs specified clearing cache time.
Clear Nginx PageSpeed cache by deleting the files
The only “rude” way I’ve found to completely remove ngx_pagespeed cache is by running a rm -rf command, it is not the best solution I wanted but it worked:
rm -rf /var/ngx_pagespeed_cache/*
After that, restart Nginx to apply changes:
service nginx restart
That’s all, at this time you should know how to flush nginx pagespeed cache using both ways, the official one recommeded by Google, and my “rude” one deleting all the files.