varnish中配置purge如下:
acl purge {
"localhost";
"192.168.55.0"/24;
}
sub vcl_recv {
# allow PURGE from localhost and 192.168.55...
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
return (lookup);
}
}
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
如果要purge: http://img.notsobad.me/xxx/abc.jpg, 在服务器上执行:
curl -X PURGE http://img.notsobad.me/xxx/abc.jpg
这样写一直报405 not allowed, 想了下,也许是访问img.notsobad.me时,走的时外网网卡,varnish识别处的ip是外网ip,根据上面的配置应该走loopback才对,so:
curl -X PURGE http://127.0.0.1/xxx/abc.jpg
即可。