nginx 使用ngx_cache_purge清除缓存

location ~ ^/myclear(/.*) {
allow 10.0.0.0/8;
allow 10.28.100.0/24;
allow 127.0.0.1;
deny all;
 
proxy_cache_purge cache_wwwme $scheme$request_method$host$1;
#proxy_cache_purge cache_wwwme $host$1$is_args$args;
}
这个location段要放在缓存前面,不然会进入到其它段而不会进入这段
 
缓存段:
location ~* \.(html|htm|gif|png|jpg|jpeg|bmp|ico|swf|txt)$ {
include proxy.conf;
proxy_cache cache_wwwme;
proxy_cache_key $scheme$request_method$host$request_uri;
proxy_cache_valid 200 304 7d;
proxy_set_header Host $host;
proxy_pass http://*.*.*.*;
}
key有nginx变量组成,比如上面
$scheme是协议:http
$request_method 请求方法:GET 等
$host www.qbaobei.com 主机名域名
$request_uri 请求uri,没有经过处理得url,请求什么uri就是什么uri
$uri 请求的uri经过处理
$is_args 如果带参数就是?,否则空
$args 请求参数
proxy_cache_purge 要清除的key要和缓存的key一致
 
比如:
请求:curl -s -x 10.28.100.222:80 http://www.***.com/**/287278.html -o /dev/null
删除cache:
$ curl -s -x 10.28.100.222:80 http://www.***.com/jfclear/**/287278.html
<html>
<head><title>Successful purge</title></head>
<body bgcolor="white">
<center><h1>Successful purge</h1>
<br>Key : httpGETwww.***.com/**/287278.html 根据配置生成的key,根据这个key做md5,然后生成缓存
<br>Path: /data/ngx_cache/wwwqbb/e/61/e805be805592871ed2f228a07fe8e61e 根据key生成的缓存路径,md5值
</center>
<hr><center>nginx/1.10.3</center>
</body>
</html>
 
根据字符串生成md5:
echo -n 'httpGETwww.***.com/**/287278.html'|md5sum|cut -d ' ' -f1
posted @ 2017-04-12 11:41  行知散人  阅读(1944)  评论(0编辑  收藏  举报