[root@node0 varnish]# vim test.vcl
sub vcl_deliver { # 定义子例程
if (obj.hits > 0){ # 判断如果命中了就在http响应首部设置X-Cache为HIT
set resp.http.X-Cache = "HIT from " server.ip;
} else { # 否则就在http响应首部设置X-Cache为MISS
set resp.http.X-Cache = "MISS";
}
}
# 在varnish的命令行中重新编译重新加载配置文件
varnish> vcl.load test1 /etc/varnish/test.vcl
200 13
VCL compiled.
vcl.use test1
200 0
varnish> vcl.show test1
200 191
backend webserver {
.host = "172.16.27.1";
.port = "80";
}
sub vcl_deliver {
if (obj.hits > 0){
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
[root@node0 varnish]# curl -I http://172.16.27.88/index.html # 也可以在命令行请求
|