国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網管 > 服務器 > 正文

Varnish purges 緩存清除 教程

2020-05-27 13:08:59
字體:
來源:轉載
供稿:網友

 Varnish的緩存清除非常復雜。無論是Varnish的清除方式還是清除時候使用的語法規則等,都是比較復雜。為了理解他,我花費了不少時間,現在我很高興我知道怎么來解釋給大家聽了。

1、Varnish有兩種方式來清除緩存,其中一種方式是通過命中對象的單一變體,所以在他命中一個沒有壓縮的對象的時候他不能清除一個已經壓縮的對象。這個方式也就是強制過期(forced expiry),他是通過設置你想清除的對象的TTL為0去強制它過期。VCL設置如下:

acl purge {"localhost";"192.0.2.14";}sub vcl_recv {if (req.request == "PURGE") {if (!client.ip ~ purge) {error 405 "Not allowed.";}lookup;}}sub vcl_hit {if (req.request == "PURGE") {set obj.ttl = 0s;error 200 "Purged.";}}sub vcl_miss {if (req.request == "PURGE") {error 404 "Not in cache.";}}

2、另外一種方式是使用purge_url,VCL設置如下:

acl purge {"localhost";"192.0.2.14";}sub vcl_recv {if (req.request == "PURGE") {if (!client.ip ~ purge) {error 405 "Not allowed.";}purge("req.url == " req.url);}

通過以上在VCL文件的設置,我們通過HTTP來執行PURGE。這意味著你現在發送了一個:

PURGE / HTTP/1.0Host: www.example.com

通過80端口給了Varnish。但是,這種執行PURGE的方式不支持正則。如果你想支持,可以按照這樣來設置VCL:

acl purge {"localhost";"192.0.2.14";}sub vcl_recv {if (req.request == "PURGE") {if (!client.ip ~ purge) {error 405 "Not allowed.";}purge("req.url ~ " req.url);}

3、對于purge的方式,除了像上邊第2點那樣設置VCL來允許PURGE外,其實我們還可以通過Varnish的管理端口發送靈活的PURGE命令來清除緩存。3.1 首先讓我們來看看管理端口的help(Varnish版本2.1)

[root@varnish4 varnish]# telnet 192.168.1.185 3500Trying 192.168.1.185...Connected to 192.168.1.185 (192.168.1.185).Escape character is ^].200 154 -----------------------------Varnish HTTP accelerator CLI.-----------------------------Type help for command list.Type quit to close CLI session.help200 377 help [command]ping [timestamp]auth responsequitbannerstatusstartstopstatsvcl.load <configname> <filename>vcl.inline <configname> <quoted_VCLstring>vcl.use <configname>vcl.discard <configname>vcl.listvcl.show <configname>param.show [-l] [<param>]param.set <param> <value>purge.url <regexp>purge <field> <operator> <arg> [&& <field> <oper> <arg>]...purge.list

3.2 help中和purge有關的命令有三個,其中purge.list是查看purge的列表,能執行purge的是purge.url和purge兩個命令。3.2.1 purge.url命令它只支持url的purge,如清除http://blog.izhoufeng.com/test.html。

[root@varnish2 varnish]# telnet 192.168.1.185 3500Trying 192.168.1.185...Connected to varnish1 (192.168.1.185).Escape character is ^].200 154 -----------------------------Varnish HTTP accelerator CLI.-----------------------------Type help for command list.Type quit to close CLI session.purge.url test.html200 0

除用CLI接口外也可以用:

/usr/local/varnish-2.1/bin/varnishadm -T 192.168.1.185:3500 purge.url ^test.html$

3.2.2 purge命令則很靈活,請看列子:清除http://izhoufeng.com/somedirectory/和目錄下的所有頁面。

purge req.http.host == izhoufeng.com && req.url ~ ^/somedirectory/.*$orpurge req.url ~ ^/somedirectory/ && req.http.host == izhoufeng.com

清除所有帶“Cache-Control: max-age=3600”的對象。

purge obj.http.Cache-Control ~ max-age=3600orpurge obj.http.Cache-Control ~ max-age ?= ?3600[^0-9]

4、對于大量清除,需要程序接口來做。4.1 通過HTTP的PURGE的接口。<span style="color: rgb(0, 0, 0); font-weight: bold;"><?php</span><span style="color: rgb(102, 102, 102); font-style: italic;">//刷新varnish緩存的函數,$ip為varnish服務器IP地址, $host為要刷新的網站域名,$url為要刷新的不含域名的URL地址</span><span style="color: rgb(0, 0, 0); font-weight: bold;">function</span> varnish_purge<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$ip</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 136);">$host</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 136);">$url</span><span style="color: rgb(0, 153, 0);">)</span> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 奇台县| 自治县| 平江县| 通海县| 安仁县| 琼海市| 丹凤县| 阿拉善左旗| 乌拉特前旗| 会理县| 都昌县| 唐海县| 凤冈县| 黑水县| 土默特左旗| 南雄市| 汾西县| 呼伦贝尔市| 河北省| 九江市| 垫江县| 临朐县| 班戈县| 广汉市| 黄骅市| 同江市| 揭阳市| 武平县| 潼南县| 莒南县| 宜兰县| 临海市| 黄石市| 富源县| 桦甸市| 宁河县| 深圳市| 馆陶县| 望都县| 伊吾县| 博乐市|