之前写过一篇如何配置nginx缓存及手动清除缓存的文章:
http://www.cnblogs.com/Eivll0m/p/4921829.html
但如果有大量缓存需要清理,手动一条条清理就比较慢了,所以写了个小脚本进行清理,脚本如下:
#!/usr/bin/env python# -*- coding: UTF-8 -*-# data:2015-12-08# author:eivll0m# 脚本用途:清除nginx静态资源缓存# 使用方法:将要清除缓存的url粘贴到/app/admin/sbin/url.txt文件中,一行放一个url,然后执行此脚本。import urllib2def purge(FILE): with open(FILE) as f: for line in f: L = line.strip().split('/') L.insert(3,'purge') req = urllib2.Request('/'.join(L)) try: response = urllib2.urlopen(req) page = response.read() print page except urllib2.HTTPError, e: print line + '缓存已清除或没有缓存!' #print 'Error code: ', e.codeif __name__ == '__main__': F = "/app/admin/sbin/url.txt" purge(F)