1.在server1
[[email protected] ~]# cat /etc/hosts 172.25.5.1 server1 www.westos.org bbs.westos.org 172.25.5.3 server
6.打开浏览器,浏览器中输入172.25.5.1:8080,出现CDN推送管理页面 7.编写varnish的默认文件vim /etc/varnish/default.vcl 添加
[[email protected] html]# vim /etc/varnish/default.vcl #设置访问控制,即白名单,允许本机和172.25.64网段和推送 acl westos{ "127.0.0.1"; ##允许本机访问 "172.25.5.0"/24; ##允许172.25.5网段的所有主机访问 } sub vcl_recv{ if(req.request == "BAN"){ if(!client.ip ~ westos){ error 405 "Not allowed."; } ban("req.url ~" + req.url); error 200 "ban added"; } } backend web1 { .host = "172.25.5.2"; .port = "80"; } backend web2 { .host = "172.25.5.3"; .port = "80"; } director lb round-robin { { .backend = web1;} { .backend = web2;} } sub vcl_recv { if (req.http.host ~ "^(www.)?westos.org") { set req.http.host = "www.westos.org"; set req.backend = lb; #return (pass); }elsif (req.http.host ~ "^bbs.westos.org") { set req.backend = web2; } else { error 404 "westos cache"; } } sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Cache = "HIT from westos.cache"; } else { set resp.http.X-Cache = "MISS from westos cache"; } return (deliver); }
8.测试