Varnish简介

1,415 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,415
On SlideShare
0
From Embeds
0
Number of Embeds
224
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Varnish简介

  1. 1. Varnish简介
  2. 2. 场景1同一时间有多个需求和项目,在本地有多个分支。经常需要切换分支来进行不同需求的开发。
  3. 3. 场景2开始开发时,在merge文件中去掉文件后面的-min,在ci前再把-min加上去。
  4. 4. 场景3许多人同时开发一个项目。需要其中一人先ci到分支,另一人up才能看到效果。不能实时的看到修改结果
  5. 5. 我的解决方案——Varnish
  6. 6. Varnish介绍Varnish,是一套高效能的反向网站快取服务器(reverseproxy server)。挪威最大的在线报纸 Verdens Gang 使用3台Varnish代替了原来的12台Squid,性能比以前更好。https://www.varnish-cache.org/
  7. 7. Varnish配置 Varnish有一个很棒的配置系统,大部分其 他的系统使用配置指令,让您打开或者关 闭一些开关。Varnish使用配置语言,这种 语言叫做“VCL”(varnish configuration language),在启动varnish时,varnish就把 VCL编译成二进制代码。
  8. 8. 状态图https://www.varnish-cache.org/trac/wiki/VCLExampleDefaultbackend default { .host = "127.0.0.1"; .port = "8080";}sub vcl_recv { return(pass);}
  9. 9. 状态图https://www.varnish-cache.org/trac/wiki/VCLExampleDefaultbackend default { .host = "127.0.0.1"; .port = "8080";}sub vcl_recv { return(pass);}
  10. 10. 127.0.0.1用户请求 varnish 修改后的请求 :8000
  11. 11. 例1 一个人有多个分支if(req.url~ "/app/platform/purchase"){ set req.url = "/style2"req.url; set req.http.X-Server = "Path-style2"; return (pass);}if(req.url~ "mainiframe/inside"){ set req.url = "/style0"req.url; set req.http.X-Server = "style0"; return (pass);}
  12. 12. 目录结构,D:workspaceApach配置Listen 8000DocumentRoot "D:/workspace"
  13. 13. 例2 自动去掉-minif((req.url!~ "(fdev|alitalk|get)-min.")&&(req.url!~"/(fdev-v3|yui|)/")){ set req.url = regsub(req.url,"-min.",".");}
  14. 14. 例3 多人合作开发backend default { .host = "127.0.0.1"; .port = "8000";}backend prerelease{ .host = "172.22.35.70"; .port = "80";}backend shijiali{ .host = "10.19.6.13"; .port = "80";}
  15. 15. if(req.url~ "/vas/hub/"){ set req.backend = shijiali; set req.http.X-Server = "Server-shijiali"; return (pass);}if(req.url~ "mainiframe/inside"){ set req.url = "/style0"req.url; set req.http.X-Server = "style0"; return (pass);}set req.backend = prerelease;set req.http.X-Server = "Server-prerelease";return (pass);
  16. 16. 127.0.0.1:8000 127.0.0.1 :8000varnish 10.19.6.13:80 172.22.35.70:80
  17. 17. 其他小应用
  18. 18. 简化版 完整版<esi:include src=“basic-esi.php?type=1”mce_src=“basic-esi.php?type=1”/>
  19. 19. Basic-esi.php
  20. 20. sub vcl_fetch { if(req.url~ "post_offer_(lite|new).htm"){ esi; } return (deliver);}

×