vcl普通配置搜索下就很多
这里介绍下 配置varnish vcl.conf 通过构造特殊Url清理缓存
比如:
在访问 http://xxx/~purge/yyyy时打开 http://xxx/yyyy 并清除掉该页缓存
sub vcl_fetch中加入
if ( req.url ~ "^/~purge/" ) {
# 判断是~purge开头的替换到~purge这个标识符
set req.url = regsub (req.url , "^/~purge/" ,"/");
return(restart);
}
sub vcl_hit 中加入
if ( req.restarts == 1){
#如果是重写了url后匹配过来的
if (!client.ip ~ purge) { #只运行特殊IP这么干哦
error 405 "Not allowed." ;
}
purge;
}
restart 这个是重点 在3.x以后的版本 purge只能在 vcl_hit中执行 不能指定地址了
附:资料 https://www.varnish-cache.org/trac/wiki/VCLExampleRestarts
Varnish配置文件VCL中的函数详解
Called after a request is received from the browser, but before it is processed.
接收到浏览器请求后,在处理请求之前调用此函数
vcl_pipe()
Called when a request must be forwarded directly to the backend with minimal handling by Varnish (think HTTP CONNECT)
当请求以varnish最小的处理而必须直接转交给后端服务时调用此函数
vcl_hash()
Called to determine the hash key used to look up a request in the cache.
当确定为请求的数据进行缓存指定哈希key时,调用此函数
vcl_hit()
Called after a cache lookup when the object requested has been found in the cache.
当在缓存中找到所要请求的数据时调用此函数
vcl_miss()
Called after a cache lookup when the object requested was not found in the cache.
当无法在缓存中找到所要请求的数据时调用此函数