如何设置Varnish不缓存某个域的链接

时间:2019-08-20 17:58:19  来源:igfitidea点击:

修改文件 /etc/varnish/defualt.vcl,

添加下面内容到 sub vcl_recv中,(在return (lookup);之前)

# dont cache myip.theitroad.local
   if (req.http.host ~ "(myip.theitroad.local)") {
     return(pass);
   }

重新启动Varnish

/etc/init.d/varnish restart

检查配置是否有效:

从系统中使用以下命令(必须安装curl),查看Age是否为0。(表示不缓存)

Hyman@theitroad:~/Desktop$ curl -I myip.theitroad.local
HTTP/1.1 200 OK
Server: Apache
Content-Type: text/html; charset=UTF-8
Accept-Ranges: bytes
Date: Thu, 03 Oct 2013 16:53:31 GMT
X-Varnish: 2015266685
Age: 0
Via: 1.1 varnish
Connection: keep-alive

Hyman@theitroad:~/Desktop$