ÒªÇó£º
²»»º´æÖ¸¶¨µÄÎļþ
vim /etc/varnish/default.vcl
sub vcl_recv {
if (req.url ~"^/test.html$"){
return(pass);
}
}
varnishadm¶¯Ì¬¼ÓÔØÅäÖÃÎļþ£º
varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082
vcl.list
200
available 0boot
available 0test1
available 0test3
active 0test4
vcl.load test5 test.vcl
200
VCL compiled.
vcl.use test5
200
VCL 'test5' now active
²»¹ÜÇëÇó¶àÉٴΣ¬Õâ¸öÎļþ¶¼²»»á±»»º´æ£º
Îļþ²»»á±»»º´æ£¬Ã¿Ò»´ÎÇëÇó¶¼Ö±½Ó´Óºó¶Ë·þÎñÆ÷È¡Êý¾Ý
[root@node220 ~]# curl -I http://192.168.2.230:6081/test.html
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Tue, 29 Aug 2017 02:11:11 GMT
Content-Type: text/html
Content-Length: 30
Last-Modified: Tue, 29 Aug 2017 02:04:27 GMT
ETag: "59a4cbab-1e"
Accept-Ranges: bytes
X-Varnish: 294967
Age: 0
Via: 1.1 varnish-v4
X-Cache: MISS from 192.168.2.230
Connection: keep-alive
[root@node220 ~]# curl -I http://192.168.2.230:6081/test.html
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Tue, 29 Aug 2017 02:11:12 GMT
Content-Type: text/html
Content-Length: 30
Last-Modified: Tue, 29 Aug 2017 02:04:27 GMT
ETag: "59a4cbab-1e"
Accept-Ranges: bytes
X-Varnish: 131121
Age: 0
Via: 1.1 varnish-v4
X-Cache: MISS from 192.168.2.230
Connection: keep-alive
ÒªÇó£º
²»»º´æÖ¸¶¨µÄĿ¼£º
/admin
/login
sub vcl_recv {
if (req.url~ "(?!)^/login" || req.url ~ "(?i)^/admin"){
return(pass);
}
}
²âÊÔ£º
ÔÚûÓÐÅäÖÃÒÔÇ°£º
[root@node220 ~]# curl -I http://192.168.2.230:6081/test_login/index.html
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Tue, 29 Aug 2017 02:21:18 GMT
Content-Type: text/html
Content-Length: 14
Last-Modified: Tue, 29 Aug 2017 02:19:20 GMT
ETag: "59a4cf28-e"
X-Varnish: 131124
Age: 0
Via: 1.1 varnish-v4
X-Cache: MISS from 192.168.2.230
Connection: keep-alive
[root@node220 ~]# curl -I http://192.168.2.230:6081/test_login/index.html
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Tue, 29 Aug 2017 02:21:18 GMT
Content-Type: text/html
Content-Length: 14
Last-Modified: Tue, 29 Aug 2017 02:19:20 GMT
ETag: "59a4cf28-e"
X-Varnish: 32 131125
Age: 5
Via: 1.1 varnish-v4
X-Cache: HIT from 192.168.2.230
Connection: keep-alive
ÅäÖÃvarnishµÄvclÒÔºó£ºÖ¸¶¨Ä¿Â¼ÏµÄÎļþ²»»á±»»º´æ£¬Ã¿Ò»´ÎÇëÇó¶¼Ö±½Ó´Óºó¶Ë·þÎñÆ÷È¡Êý¾Ý
vim /etc/varnish/default.vcl
sub vcl_recv {
if (req.url~ "(?i)^/test_login" || req.url ~ "(?!)^/rsc") {
return(pass);
}
}
[root@node220 ~]# curl -I http://192.168.2.230:6081/test_login/index.html
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Tue, 29 Aug 2017 02:24:36 GMT
Content-Type: text/html
Content-Length: 14
Last-Modified: Tue, 29 Aug 2017 02:19:20 GMT
ETag: "59a4cf28-e"
Accept-Ranges: bytes
X-Varnish: 294975
Age: 0
Via: 1.1 varnish-v4
X-Cache: MISS from 192.168.2.230
Connection: keep-alive
[root@node220 ~]# curl -I http://192.168.2.230:6081/test_login/index.html
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Tue, 29 Aug 2017 02:24:37 GMT
Content-Type: text/html
Content-Length: 14
Last-Modified: Tue, 29 Aug 2017 02:19:20 GMT
ETag: "59a4cf28-e"
Accept-Ranges: bytes
X-Varnish: 37
Age: 0
Via: 1.1 varnish-v4
X-Cache: MISS from 192.168.2.230
Connection: keep-alive