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 {} \;
- sandip's blog
- Login or register to post comments
Comments
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/"s ubstr($1,length($1),1)"/& quot;substr($1,length($1)-2,2) "/"$1}'
Example:
$ echo -n "http://www.linuxweb.com/ path/to/test.html" | md5sum be6d -
6d | awk '{print "/var/cache/nginx/"s ubstr($1,length($1),1)"/& quot;substr($1,length($1)-2,2) "/"$1}' 3843b4a5a6314c95d610c5be6d
48a17b3843b4a5a6314c95d610c5
$ echo 48a17b3843b4a5a6314c95d610c5be
/var/cache/nginx/d/e6/48a17b
substr($1,length($1),1) -- print the last character.
substr($1,length($1)-2,2) -- print the third and second character from the end.
find /var/cache/nginx -type f -exec grep -l "KEY: https://" {} \; | xargs rm -f