Varnish's cache cleanup is very complicated. Whether it is Varnish's cleanup or grammar rules used when it is cleaned up, it's more complicated. In order to understand him, I spent a lot of time, and now I am very happy that I know how to explain it to everyone. Varnish has two ways to clear the cache. One way is by hitting a single variant of the object, so he can't clear an already compressed object when he hits an uncompressed object. This method is also forced expiry. It forces the expiration by setting the TTL of the object you want to clear to 0. The VCL settings are as follows:
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, another way is to use purge_url, VCL settings are as follows :
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);}
Through the above settings in the VCL file, we execute PURGE via HTTP. This means that you have now sent one:
PURGE /HTTP/1.0Host: www.example.com
Varnish was given via port 80. However, this way of implementing PURGE does not support regularity. If you want to support it, you can set VCL like this:
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, for the way of purge In addition to setting VCL to allow PURGE as in point 2 above, we can also clear the cache by sending flexible PURGE commands through Varnish's management port. 3.1 Let's first take a look at the help port for the management port (Varnish version 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 There are three commands related to purge in help, where purge.list is a list of purges, and purge is fine.url And purge two commands. 3.2.1 The purge.url command only supports the url of the purge, such as clearing 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
In addition to using the CLI interface, you can also use:
/usr/local/varnish-2.1/bin/varnishadm -T 192.168.1.185:3500 purge.url ^test.html$
3.2.2 The purge command is very flexible, see the list: Clear http: //izhoufeng.com/somedirectory/and all pages in the directory.
purge req.http.host == izhoufeng.com && req.url ~ ^/somedirectory/.*$orpurge req.url ~ ^/somedirectory/&& req.http.host == izhoufeng.com
Clear all objects with "Cache-Control: max-age=3600”.
purge obj.http.Cache-Control ~ max-age=3600orpurge obj.http.Cache-Control ~ max-age ?= ?3600[^0-9]
4, for A lot of cleanup requires a program interface to do it. 4.1 PURGE interface through HTTP. <span style="color: rgb(0, 0, 0); font-weight: bold;"><?php</span><span style="color: rgb(102, 102 , 102); font-style: italic;">//Refresh the varnish cache function, $ip is the varnish server IP address, $host is the website domain name to be refreshed, $url is the URL to be refreshed without domain name Address </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>
If you have used Linux for a while and feel that the hard disk is not enough, you
If you want to try a desktop system other than Mac and Windows, Linux should definitely be your fir
For beginner Linux (me too), I dont want to mess with Linux in the virtual machine, and I dont want
Introduction to Soft InterruptsInsert processing that can be deferred from the hard interrupt handl
Linux regularly performs tasks. Implementation Tutorial
How to read multiple files at the same time in the shell
Basic knowledge about linux graphical interface
How to modify the Linux host name
Fault location technology on Red Hat Linux
Analyze the Linux firewall framework from five aspects
Linux driver development details
Method for adjusting screen refresh rate under Linux system
Summary of dual network card configuration practice under Linux system
Master advanced - in-depth analysis of BOOT.INI experience skills
WinXP boot shows pink is going on?
Windows XP system cannot empty the recycle bin
How to start Windows Security Center service in Windows 7
Win7 manually enable Windows Event Log service error solution
How Win10 uses security and maintenance features to make systems more secure
What should I do if the Win7 system web game cannot be played?
How to split the Win10 window? Win10 intelligent split screen introduction
May I ask if my computer configuration can be watched by Pioneer Pioneer or gta5?