前言
ngx_cache_purge是第三方模块,用于清理nginx内置模块(proxy_cache)缓存。就像CDN的清理缓存的url命令一样。
模块下载地址
https://github.com/FRiCKLE/ngx_cache_purge
安装
./configure --prefix=/opt/nginx/nginx-1.9.6 --add-module=/opt/soft/ngx_cache_purge-2.3
make
make install
配置
# Cache_proxy Purge,这个url中,必须以波浪号开头,不要加"^"
location ~ /purge(/.*) {
proxy_cache_purge content $host:$server_port$1$is_args$args;
access_log logs/cache.log cache_log;
}
# 如果请求头里有信息:Cache-Control:no-cache,则缓存规则失效
location /cache_ehcache-2.10.0_web {
proxy_pass http://192.168.56.1:8080/cache_ehcache-2.10.0_web;
proxy_cache content; #根keys_zone后的内容对应
proxy_cache_valid 200 304 301 302 1h; #哪些状态缓存多长时间
proxy_cache_methods GET; # 默认是get和head
proxy_cache_valid any 3s; #其他的缓存多长时间
proxy_cache_key $host:$server_port$uri$is_args$args; #通过key来hash,定义KEY的值
#缓存的具体key值是: [host]192.168.56.2 [server_port]8080 [uri]/cache_ehcache-2.10.0_web/expire [is_args] [args]-
proxy_cache_min_uses 3; #只要统一个url,在磁盘文件删除之前,总次数访问到达3次,就开始缓存。
proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment; # 如果任何一个参数值不为空,或者不等于0,nginx就不会>查找缓存,直接进行代理转发
#增加输出日志
access_log logs/cache.log cache_log;
}
测试效果
输入URL:http://192.168.56.2:8080/cache_ehcache-2.10.0_web/expire?a=222
清理缓存:http://192.168.56.2:8080/purge/cache_ehcache-2.10.0_web/expire?a=222
之后再次访问原来的url,缓存就会失效了。
高级用法
1.结合nginx的白名单/黑名单功能:http://phl.iteye.com/blog/2251767
2.结合nginx的auth使用:http://phl.iteye.com/blog/2251771
3.nginx的代理缓存设置:http://phl.iteye.com/blog/2253442
这样,安全控制得到了保障。如果是nginx集群,可以使用python进行集群的清理。
参考文章
nginx之location配置
http://blog.csdn.net/hellochenlian/article/details/44655547
Nginx Purge清除缓存配置
http://www.myhack58.com/Article/sort099/sort0100/2013/38043.htm
nginx第三方插件
https://www.nginx.com/resources/wiki/modules/?highlight=purge
- 大小: 105.9 KB
- 大小: 88.2 KB
分享到:
相关推荐
ngx_cache_purge 是 nginx 模块,此模块可以清理 nginx 的 FastCGI、proxy、 SCGI 和 uWSGI 的缓存。配置指令(相同位置语法)fastcgi_cache_purgesyntax: fastcgi_cache_purge on|off|<method> [from all|<ip> [.....
ngx_cache_purge_2.4.2.tar.gz
nginx_cache_purge,用于清楚nginx缓存的小工具
ngx_slowfs_cache 是 nginx 模块,允许缓存静态文件(使用 root 指令管理)。 这使得能够为存储在慢文件系统上的文件...}清理缓存需要借助插件 ngx_cache_purge 使用案例:nginx扩展模型ngx_slowfs_cache本地静态缓存
ngx_cache_purge-1.3.tar.gz
nginx-1.0.12_ngx-cache-purge1.5.tar.gz
在功能上,Nginx已经具备Squid所拥有的Web缓存加速功能、清除指定URL...–by 张宴 下载2011-05-03更新的最新版1.3wget http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gztar zxf ngx_cache_purge-1.3.tar.g
利用Nginx的proxy_cache搭建缓存服务器一:编译ngx_cache_purge 1、Nginx的Proxy_cache是根据Key值md5哈希存储缓存,支持任意的Key,例如你可以根据”域名、URI、参数”组合成key,也支持非200状态码,如404/302等...
fastdfs-5.05.tar.gz : FastDFS安装主文件包 libfastcommon-master.zip: FastDFS文件系统依赖包 nginx-1.8.1.tar.gz:nginx安装包 fastdfs-nginx-module_v1.16.tar.gz: nginx下...ngx_cache_purge-2.1.tar.gz:缓存
包含以下模块,源自CentOS 7.6.1810 x86_64 系统构建 ``` ngx_devel_kit ...ngx_cache_purge nginx-sticky-module openssl pcre-8.43 ngx_http_substitutions_filter_module dav-ext security vts rtmp ```
fastdfs所需的最全安装包及依赖包 FastDFS_v5.05.tar.gz、fastdfs-nginx-module_v1.16.tar.gz、libfastcommon-master.zip、nginx-1.11.4.tar.gz、ngx_cache_purge-2.3.tar.gz
(注意注意,里面有个文件libfastcommon_v1.01.tar.gz不太好用,大家可以去这个地址 http://download.csdn.net/download/simuhunluo/10114036 单独下载一个可用的1.07版本)(在这里上传... ngx_cache_purge-2.3.tar.gz
Nginx 0.8.32版本,proxy_cache和fastcgi_cache已经比较完善,加上第三方的ngx_cache_purge模块(用于清除指定URL的缓存),已经可以完全取代Squid。 在功能上,Nginx已经具备Squid所拥有的Web缓
nginx-upload-module安装依赖包,包括了 ngx_cache_purge-2.3.tar.gz,zlib-1.2.11.tar.gz,pcre2-10.32.tar.gz,nginx-upload-module-2.2.zip
包含模块nginx, nginx doc, Lua, Naxsi, Rtmp, HttpSubsModule,echo-nginx, lower_upper_case, headers-more,auth_ldap, set-misc, lua-...ngx_cache_purge, nginx-http-concat, nginx-vod-module,nginx-module-vts
cache_purge3、安装需要的依赖软件包yum -y install gcc openssl openssl-devel pcre-devel pcre ngx_cache_purge4、下载trngine-2.2.0tar.gz5、解压tengine-2.2.0.tar.gztar -zxvf tengine-2.2.0.tar.gz6...
用于编译安装nginx1.12.0版本,适合本篇文章所用,包括:master.tar.gz,nginx-1.12.0.tar.gz,ngx_cache_purge-2.3.tar.gz,资源就免费分享了
nginx-1.11.3.tar.gz,echo-nginx-module-0.59.tar.gz,ngx_cache_purge-2.3.tar.gz,nginx_upstream-fair-a18b409.tar.gz,keepalived
ngx_cache_purge-2.1.tar.gz pcre-8.34.tar.gz zlib-1.2.8.tar.gz 安装方法:...
Nginx安装配置1.源码安装上传openssl-1.0.1s.tar.gz、pcre-8.38.tar.bz2、ngx_cache_purge-2.3.tar