clear out nginx cache

If you are switching out static content that have gotten cached in nginx, the head of the cached files usually stores the file path that can be greped for and the file removed. One you hit the url again, it will recreate the new cached file at the same location.

find /var/cache/nginx -type f -exec grep -l /path/to/oldfile.css {} \;

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

removing single nginx cache file

If you are just removing a single file, a much faster way would be to get path from the md5 hash of the proxy_cache_key that was used. The proxy_cache_key would be something like, "$scheme://$host$request_uri":

Here's a one liner to get the file path to remove:

echo -n "$scheme://$host$request_uri" | md5sum | awk '{print "/var/cache/nginx/"substr($1,length($1),1)"/"substr($1,length($1)-2,2)"/"$1}'

Example:

$ echo -n "http://www.linuxweb.com/path/to/test.html" | md5sum
48a17b3843b4a5a6314c95d610c5be6d  -

$ echo 48a17b3843b4a5a6314c95d610c5be6d | awk '{print "/var/cache/nginx/"substr($1,length($1),1)"/"substr($1,length($1)-2,2)"/"$1}'
/var/cache/nginx/d/e6/48a17b3843b4a5a6314c95d610c5be6d

substr($1,length($1),1) -- print the last character.
substr($1,length($1)-2,2) -- print the third and second character from the end.

clear out https url

find /var/cache/nginx -type f -exec grep -l "KEY: https://" {} \; | xargs rm -f

Comment