栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > 服务器

varnish 配置文件分享(sens杨 注释)

服务器 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

varnish 配置文件分享(sens杨 注释)

前言:
varnish 为目前新兴起来的软件,由于中文文档比较少,配置文件比较复杂,所以在运用起来也是特别的费劲。一个偶然的机会在一个群里,有位varnish高手( sens杨 )发表了一篇他对varnish配置文件理解的文档。对于学者来说很有价值。所以转载了过来。

原文如下:

varnish配置文件原文地址:http://groups.drupal.org/node/63203

注:红色字体是英文的直接翻译,有些地方翻译的不好
绿色部分是一些思考,这个配置对自身的业务配置的很详细,现在对除了cookie和TTL那部分外其他可以理解80%,慢慢学习体会

  1. backend default {  
  2.   .host = "127.0.0.1";  
  3.   .port = "8008";  
  4.   .connect_timeout = 600s;  
  5.   .first_byte_timeout = 600s;  
  6.   .between_bytes_timeout = 600s;  
  7. }  
  8.   
  9. backend lighttpd {  
  10.   .host = "127.0.0.1";  
  11.   .port = "81";  
  12.   .connect_timeout = 600s;  
  13.   .first_byte_timeout = 600s;  
  14.   .between_bytes_timeout = 600s;  
  15. }  
  16.   
  17. acl techmission_internal {  
  18.   "localhost";  
  19.   "127.0.0.1";  
  20. }  
  21. sub vcl_recv {  
  22.   // Allow a grace period for offering "stale" data in case backend lags (http://varnish-cache.org/wiki/VCLExampleGrace)  
  23. // 如果backend数据滞后,允许为“过时”数据提供一个宽松期  
  24.   set req.grace = 5m;  
  25.   // block outside world from our test sites  
  26. // 阻止非自己说测试网站(的数据访问)  
  27.   if ((req.http.host ~ "www.domain1.org|www.domain2.org") && !(client.ip ~ techmission_internal) && !(req.url ~ "^/ad|^/files")) {  
  28.     error 403 "Forbidden";  
  29.   }  
  30.   if((req.url ~ "/server-status" || req.url ~ "/whm-server-status") && !(client.ip ~ techmission_internal)) {  
  31.   error 404 "Not Found";  
  32.   }  
  33.   // add ping url to test Varnish status  
  34. // 增加ping URL测试varnish状态(这个功能使用大部分vcl都没配置,可以增加一个监控状态)  
  35.   if (req.request == "GET" && req.url ~ "/varnish-ping") {  
  36.   error 200 "OK";  
  37.   }  
  38.   
  39. // 使host头规范化,以减少在cache中变化(这个为什么会说变化呢?)  
  40. if (req.http.host == "domain.org" && req.url !~ "^/blogs") {  
  41.   set req.http.host = "www.domain.org";  
  42. }  
  43.   
  44.   
  45. //规范化Accept-Encoding以减少Vary:Accept-Encoding影响(cf),也要注意Vary: User-Agent认为是有害的  
  46.   
  47.   if (req.http.Accept-Encoding) {  
  48. //if先判断是否可以存在,是为了缩小处理范围?  
  49. //看到的其他大部分配置直接就下面了,没有先判断Accept-Encoding是否存在,这点可以再考虑考虑  
  50. //现在有req.can_gzip参数了,判断客户端是否接受压缩代码传输  
  51.     if (req.url ~ ".(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {  
  52.       // Don't compress already-compressed files  
  53.       remove req.http.Accept-Encoding;  
  54.     }   
  55.     elsif (req.http.Accept-Encoding ~ "gzip") {  
  56.         set req.http.Accept-Encoding = "gzip";  
  57.     }   
  58.     elsif (req.http.Accept-Encoding ~ "deflate") {  
  59.         set req.http.Accept-Encoding = "deflate";  
  60.     }   
  61.     else {  
  62.       // unknown algorithm  
  63. // 不了解运算  
  64.       remove req.http.Accept-Encoding;  
  65.     }  
  66.   }  
  67.   
  68.   // Remove has_js and Google Analytics __* cookies. Also remove collapsiblock cookies.  
  69. //删除has_js和谷歌统计__*的cookies,同时删除collapsiblock cookies  
  70.   set req.http.cookie = regsuball(req.http.cookie, "(^|;s*)(__[a-z]+|__utma_a2a|has_js|collapsiblock)=[^;]*", "");  
  71.   // Remove JSESSIONID cookie from ChristianVolunteering.org static files and pages that are same for all users  
  72. //从ChristianVolunteering.org静态文件和网页中删除JSESSIONID cookie,所有的用户是一样(处理)的  
  73.     if (req.http.host ~ "christianvolunteering.org" &&  
  74.          (req.url ~ "^/$" ||  
  75.           req.url ~ "(searchform|advancedsearch|shorttermmissions|recruitvolunteers|volunteergettingstarted|virtualvolunteer|organizationsearch|abs-bible-outreach|ab*ecutive-volunteers|abs-traveling-engagement-center|churchinstructions|sitemap|city|virtual|organizationlistings|orglistings7407|technology|volunteerlistings|forgotpassword|churchvolunteer|churchvolunteering|servicetrip|region|citysitemap|searchformadv|personalitytest|groupvolunteering|disasterreliefvolunteering|disasterrelief|internships|christiangapyear|about|FAQs|bookrecommendations|contact|pressrelease|training|volunteerstart|volunteerstories|articles).jsp$" ||  
  76.           req.url ~ "org/org[0-9]+.jsp$" ||  
  77.           req.url ~ "org/opp[0-9]+.jsp$" ||  
  78.           req.url ~ "orglistings[0-9]+.jsp$" ||  
  79.           req.url ~ "org/[^/]+.jsp$" ||  
  80.           req.url ~ "volunteer/[^/]+.jsp$")  
  81.         ) {   
  82.     set req.http.cookie = regsuball(req.http.cookie, "(^|;s*)(JSESSIONID)=[^;]*", "");  
  83.   }  
  84.   // Remove a ";" prefix, if present.  
  85. //如果有”;”前缀,则删除  
  86.   set req.http.cookie = regsub(req.http.cookie, "^;s*", "");  
  87.   // Remove empty cookies.  
  88. // 删除空cookies  
  89.   if (req.http.cookie ~ "^s*$") {  
  90.     unset req.http.cookie;  
  91.   }   
  92.   
  93.   // exclude umjobs and gospelpedia test sites  
  94. // 排除umjos和gospelpedia测试站点  
  95.   if (req.http.host ~ "domain1.org" || req.http.host ~ "domain2.org") {  
  96.     return (pass);  
  97.   }  
  98.   
  99.   // exclude the cron and supercron pages  
  100. // 排除cron和supercron网页  
  101.   if (req.url ~ "cron.php") {  
  102.     return (pass);  
  103.   }  
  104.   // exclude dynamic pages (as did Boost)  
  105. // 排除动态网页(也是提高(处理))  
  106.   if (req.http.host ~ "domain.org" && req.url ~ "^/(user/login|user/password|user/register|logout|cart|post-blog|site-feedback|cgi-bin/webscr|redirect-home|cv-enroll|recommended-content|node/8755|node/8830|node/8351|node/8757|node/8831|cart/(.*)|uc_paypal/(.*)|civicrm/(.*)|admin/(.*)|recommended-content/(.*)|comment/reply/(.*)|node/add/(.*))" ) {  
  107.     return (pass);  
  108.   }  
  109.   
  110.   // exclude in case of Referer Theme  
  111. // 排除Referer的一些主题  
  112.   if (req.http.host ~ "domain.org" && req.http.referer ~ "www.christianvolunteering.org|worldvision.christianvolunteering.org|ccda.christianvolunteering.org|www.ccda.org|www.urbanresource.net|mobile.urbanministry.org|www.ministeriourbano.com") {  
  113.     return (pass);  
  114.   }  
  115.     
  116. // 修复Moodle规则  
  117.    // Cache Moodle theme files  
  118. //缓存Moodle主题文件  
  119.    if (req.url ~ "/pix/.*.gif$") {  
  120.      return (lookup);  
  121.    }  
  122.   
  123.     // Moodle doesn't like to be cached, passing  
  124. //Moodle主题不能缓存的就pass  
  125.     if (req.http.cookie ~ "(MoodleSession|MoodleSessionTest)") {  
  126.       return (pass);  
  127.     }  
  128.     if (req.http.host == "www.domain.edu" && req.url ~ "^/courses") {  
  129.       return (pass);  
  130.     }  
  131.     if (req.url ~ "file.php") {  
  132.       return (pass);  
  133.     }  
  134.   
  135.     // WPMU themes are not playing well with static file caching  
  136. //WPMU主题使用静态文件缓存运行的不太好  
  137.     if (req.http.host == "domain.org" && req.url ~ "/blogs/(.*)/wp-content/themes") {  
  138.       return (pass);  
  139.     }  
  140.     
  141.     
  142.   
  143.  //删除那些阻止缓存的Set-cookie头  
  144.   // Don't have cookies on static files (gchaix says may cause loss of session; I haven't observed that)  
  145.     if (req.url ~ ".(gif|jpg|swf|css|js|png|jpg|jpeg|gif|png|tiff|tif|svg|swf|ico|doc|ppt|pps|xls|odc|odb|odf|odg|odi|odp|ods|odt|sxc|sxd|sxi|sxw)$") {  
  146.     remove obj.http.Set-cookie;  
  147.   }  
  148.   
  149.   // Don't set session cookie on ChristianVolunteering.org static files or pages that are same for all users  
  150. //对于(头)ChristianVolunteering.org的静态文件和网页,对所有用户不设置session cookie  
  151.     if (req.http.host ~ "christianvolunteering.org" &&  
  152.          (req.url ~ "^/$" ||  
  153.           req.url ~ "(searchform|advancedsearch|shorttermmissions|recruitvolunteers|volunteergettingstarted|virtualvolunteer|organizationsearch|abs-bible-outreach|ab*ecutive-volunteers|abs-traveling-engagement-center|churchinstructions|sitemap|city|virtual|organizationlistings|orglistings7407|technology|volunteerlistings|forgotpassword|churchvolunteer|churchvolunteering|servicetrip|region|citysitemap|searchformadv|personalitytest|groupvolunteering|disasterreliefvolunteering|disasterrelief|internships|christiangapyear|about|FAQs|bookrecommendations|contact|pressrelease|training|volunteerstart|volunteerstories|articles).jsp$" ||  
  154.           req.url ~ "org/org[0-9]+.jsp$" ||  
  155.           req.url ~ "org/opp[0-9]+.jsp$" ||  
  156.           req.url ~ "orglistings[0-9]+.jsp$" ||  
  157.   req.url ~ "org/[^/]+.jsp$" ||  
  158.           req.url ~ "volunteer/[^/]+.jsp$")  
  159.         ) {     
  160.     set obj.http.Set-cookie = regsuball(req.http.cookie, "(^|;s*)(JSESSIONID)=[^;]*", "");  
  161.     // Remove empty set-cookie.  
  162.     if (obj.http.Set-cookie ~ "^s*$") {  
  163.       unset obj.http.Set-cookie;  
  164.     }  
  165.   }  
  166.   
  167.   
  168.   
  169. // If on www.urbanministry.org or static.urbanministry.org, extend TTL by default (pt. 1)  
  170. //对于www.urbanministry.org或static.urbanministry.org,默认情况下扩展TTL  
  171.   if (req.http.host == "www.domain.org" || req.http.host == "static.domain.org") {  
  172.     set obj.http.X-TTL-Extend = "YES";  
  173.   }  
  174.   
  175.   // If on cityvision.edu, but not in Moodle, or if on blazinggrace.org, but not in forums, or if on techmission.org, change obj.ttl  
  176. //如果主机头是cityvision.edu但是不在Moodle中,或者主机头是blazinggrace.org,但不在forums中,或者主机头是techmission.org,更改obj.ttl  
  177.   if ((req.http.host ~ "domain.edu" && req.url !~ "/courses") || (req.http.host ~ "blazinggrace.org" && req.url !~ "/forums")  || (req.http.host ~ "techmission.org")) {  
  178.    set obj.ttl = 7d;  
  179.    set obj.http.X-Extended-TTL = "7d";  
  180. }  
  181.   
  182. if (obj.status == 404) {   
  183.    set obj.ttl = 1s;   
  184. if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  185. }   
  186.   
  187.     
  188.   
  189.   if (!obj.cacheable) {  
  190.     set obj.http.X-Cacheable = "NO: Varnish says not cacheable " obj.http.X-Cacheable;  
  191.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  192.   }  
  193.   
  194.   
  195.   // exclude umjobs and gospelpedia test sites  
  196. // 排除umjobs和gospelpedia测试站点  
  197.   if (req.http.host ~ "domain1.org" || req.http.host ~ "domain2.org") {  
  198.     set obj.http.X-Cacheable = "NO: Test domain " obj.http.X-Cacheable;  
  199.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  200.   }  
  201.   
  202.   if (obj.http.Set-cookie) {  
  203.     set obj.http.X-Cacheable = "NO: Set-cookie " obj.http.X-Cacheable;  
  204.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  205.   }  
  206.   
  207.   if (req.http.cookie ~ "DRUPAL_UID|SESS") {  
  208.     set obj.http.X-Cacheable = "NO: Got Session " obj.http.X-Cacheable;  
  209.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  210.   }  
  211.   
  212.   if (obj.http.Cache-Control ~ "private" || obj.http.Cache-Control ~ "no-cache") {  
  213.     set obj.http.X-Cacheable = "NO: Cache-Control set to not cache " obj.http.X-Cacheable;  
  214.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  215.   }  
  216.   
  217.   if (req.url ~ "cron.php") {  
  218.     set obj.http.X-Cacheable = "NO: Cron job " obj.http.X-Cacheable;  
  219.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  220.   }  
  221.   
  222.   if (req.http.host ~ "domain.org" && req.url ~ "^/(user/login|user/password|user/register|logout|cart|post-blog|site-feedback|cgi-bin/webscr|redirect-home|cv-enroll|recommended-content|node/8755|node/8830|node/8351|node/8757|node/8831|cart/(.*)|uc_paypal/(.*)|civicrm/(.*)|admin/(.*)|recommended-content/(.*)|comment/reply/(.*)|node/add/(.*))" ) {  
  223.     set obj.http.X-Cacheable = "NO: Drupal un-cacheable path " obj.http.X-Cacheable;  
  224.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  225.   }  
  226.   
  227.   if (req.http.host ~ "domain.org" && req.http.referer ~ "www.christianvolunteering.org|worldvision.christianvolunteering.org|ccda.christianvolunteering.org|www.ccda.org|www.urbanresource.net|mobile.urbanministry.org|www.ministeriourbano.com") {  
  228.     set obj.http.X-Cacheable = "NO: Referer Theme " obj.http.X-Cacheable;  
  229.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  230.   }  
  231.   
  232.   if (req.request == "POST") {  
  233.     set obj.http.X-Cacheable = "NO: POST request " obj.http.X-Cacheable;  
  234.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  235.   }  
  236.   
  237.   if (req.http.Authorization) {  
  238.     set obj.http.X-Cacheable = "NO: HTTP Authentication " obj.http.X-Cacheable;  
  239.     if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; }  
  240.   }  
  241.   
  242.   // extend TTL for urbanministry.org objects (but not panels, views, or quicktabs); invalidation thru varnish.module + um_common.module  
  243. //为urbaministry.org对象扩展TTL(不是面板、视图,或者quicktabs);经过varnish.module + um_common.module失效  
  244.   if((req.http.host == "www.domain.org" || req.http.host == "static.domain.org") && obj.http.X-TTL-Extend == "YES" && !obj.http.X-Cache-Type) {  
  245.     set obj.ttl = 7d;  
  246.     set obj.http.X-Extended-TTL = "7d";  
  247.   }  
  248.   
  249. }  
  250. sub vcl_deliver {  
  251. # return (deliver);  
  252.   // add cache hit data  
  253. // 增加缓存命中数据  
  254.   if (obj.hits > 0) {  
  255.     // if hit add hit count  
  256. // 如果命中,增加命中数  
  257.     set resp.http.X-Cache = "HIT";  
  258.     set resp.http.X-Cache-Hits = obj.hits;  
  259.     // set resp.http.X-Cache-Served-URL = "SERVED " obj.http.X-Request-URL; // http headers are apparently not accessible in vcl_deliver  
  260. //在vcl_deliver中http头明显不可访问  
  261.     // set resp.http.X-Cache-TTL = obj.ttl; // string representation not implemented yet (currently on 2.0.5)  
  262.   }  
  263.   else {  
  264.     set resp.http.X-Cache = "MISS";  
  265.   }  
  266. }  
  267.   
  268. //指定error子程序,对用户有好些  
  269. sub vcl_error {  
  270. if(obj.status == 503) {  
  271.     set obj.http.Content-Type = "text/html; charset=utf-8";  
  272.     synthetic {"  
  273.   
  274. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
  275.   
  276.     
  277.     "} obj.status " " obj.response {"  
  278.   
  279.     
  280.     Error "} obj.status " " obj.response {"  
  281.     

    "} obj.response {"

      
  282. Sorry we missed you!

      
  283. We are currently upgrading our websites to serve you better. We should be up again soon.

      
  284. If you still receive this message 30 minutes from now, please email webmaster@techmission.org.

      
  285.     Guru Meditation:  
  286.     

    XID: "} req.xid {"

      
  287.     
      
  288.       
  289.        Served by "http://www.varnish-cache.org/">Varnish cache server  
  290.       
  291.     
  292.   
  293. "};  
  294.     return (deliver);  
  295. }  
  296. elsif(obj.status == 403) {  
  297.     set obj.http.Content-Type = "text/html; charset=utf-8";  
  298.     synthetic {"  
  299.   
  300. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
  301.   
  302.     
  303.     "} obj.status " " obj.response {"  
  304.   
  305.     
  306.     Error "} obj.status " " obj.response {"  
  307.     

    "} obj.response {"

      
  308. TechMission Developer Access Only  
  309. This page is only accessible to our staff. Please visit our main websites www.techmission.org,www.urbanministry.org, and " title="www.christianvolunteering.org.  

  310. " style="color: rgb(2, 122, 198); font-weight: bold; text-decoration: none; ">www.christianvolunteering.org.

      
  311.   
  312.     Guru Meditation:  
  313.     

    XID: "} req.xid {"

      
  314.     
      
  315.       
  316.        Served by "http://www.varnish-cache.org/">Varnish cache server  
  317.       
  318.     
  319.   
  320. "};   
  321.     return (deliver);  
  322. }  
  323. else {  
  324.     set obj.http.Content-Type = "text/html; charset=utf-8";  
  325.     synthetic {"  
  326.   
  327. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
  328.   
  329.     
  330.     "} obj.status " " obj.response {"  
  331.   
  332.     
  333.     Error "} obj.status " " obj.response {"  
  334.     

    "} obj.response {"

      
  335.     Guru Meditation:  
  336.     

    XID: "} req.xid {"

      
  337.     
      
  338.       
  339.        Served by "http://www.varnish-cache.org/">Varnish cache server  
  340.       
  341.     
  342.   
  343. "};   
  344.     return (deliver);  
  345. }  

在这里感谢 sens杨 同学对配置文档的解释。

下面考高分网小编特整理的没有前面数字的文件方法大家使用

backend default { 
 .host = "127.0.0.1"; 
 .port = "8008"; 
 .connect_timeout = 600s; 
 .first_byte_timeout = 600s; 
 .between_bytes_timeout = 600s; 
} 
 
backend lighttpd { 
 .host = "127.0.0.1"; 
 .port = "81"; 
 .connect_timeout = 600s; 
 .first_byte_timeout = 600s; 
 .between_bytes_timeout = 600s; 
} 
 
acl techmission_internal { 
 "localhost"; 
 "127.0.0.1"; 
} 
sub vcl_recv { 
 // Allow a grace period for offering "stale" data in case backend lags (http://varnish-cache.org/wiki/VCLExampleGrace) 
// 如果backend数据滞后,允许为“过时”数据提供一个宽松期 
 set req.grace = 5m; 
 // block outside world from our test sites 
// 阻止非自己说测试网站(的数据访问) 
 if ((req.http.host ~ "www.domain1.org|www.domain2.org") && !(client.ip ~ techmission_internal) && !(req.url ~ "^/ad|^/files")) { 
  error 403 "Forbidden"; 
 } 
 if((req.url ~ "/server-status" || req.url ~ "/whm-server-status") && !(client.ip ~ techmission_internal)) { 
 error 404 "Not Found"; 
 } 
 // add ping url to test Varnish status 
// 增加ping URL测试varnish状态(这个功能使用大部分vcl都没配置,可以增加一个监控状态) 
 if (req.request == "GET" && req.url ~ "/varnish-ping") { 
 error 200 "OK"; 
 } 
 
// 使host头规范化,以减少在cache中变化(这个为什么会说变化呢?) 
if (req.http.host == "domain.org" && req.url !~ "^/blogs") { 
 set req.http.host = "www.domain.org"; 
} 
 
 
//规范化Accept-Encoding以减少Vary:Accept-Encoding影响(cf),也要注意Vary: User-Agent认为是有害的 
 
 if (req.http.Accept-Encoding) { 
//if先判断是否可以存在,是为了缩小处理范围? 
//看到的其他大部分配置直接就下面了,没有先判断Accept-Encoding是否存在,这点可以再考虑考虑 
//现在有req.can_gzip参数了,判断客户端是否接受压缩代码传输 
  if (req.url ~ ".(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") { 
   // Don't compress already-compressed files 
   remove req.http.Accept-Encoding; 
  }  
  elsif (req.http.Accept-Encoding ~ "gzip") { 
    set req.http.Accept-Encoding = "gzip"; 
  }  
  elsif (req.http.Accept-Encoding ~ "deflate") { 
    set req.http.Accept-Encoding = "deflate"; 
  }  
  else { 
   // unknown algorithm 
// 不了解运算 
   remove req.http.Accept-Encoding; 
  } 
 } 
 
 // Remove has_js and Google Analytics __* cookies. Also remove collapsiblock cookies. 
//删除has_js和谷歌统计__*的cookies,同时删除collapsiblock cookies 
 set req.http.cookie = regsuball(req.http.cookie, "(^|;s*)(__[a-z]+|__utma_a2a|has_js|collapsiblock)=[^;]*", ""); 
 // Remove JSESSIonID cookie from ChristianVolunteering.org static files and pages that are same for all users 
//从ChristianVolunteering.org静态文件和网页中删除JSESSIonID cookie,所有的用户是一样(处理)的 
  if (req.http.host ~ "christianvolunteering.org" && 
     (req.url ~ "^/$" || 
     req.url ~ "(searchform|advancedsearch|shorttermmissions|recruitvolunteers|volunteergettingstarted|virtualvolunteer|organizationsearch|abs-bible-outreach|ab*ecutive-volunteers|abs-traveling-engagement-center|churchinstructions|sitemap|city|virtual|organizationlistings|orglistings7407|technology|volunteerlistings|forgotpassword|churchvolunteer|churchvolunteering|servicetrip|region|citysitemap|searchformadv|personalitytest|groupvolunteering|disasterreliefvolunteering|disasterrelief|internships|christiangapyear|about|FAQs|bookrecommendations|contact|pressrelease|training|volunteerstart|volunteerstories|articles).jsp$" || 
     req.url ~ "org/org[0-9]+.jsp$" || 
     req.url ~ "org/opp[0-9]+.jsp$" || 
     req.url ~ "orglistings[0-9]+.jsp$" || 
     req.url ~ "org/[^/]+.jsp$" || 
     req.url ~ "volunteer/[^/]+.jsp$") 
    ) {  
  set req.http.cookie = regsuball(req.http.cookie, "(^|;s*)(JSESSIONID)=[^;]*", ""); 
 } 
 // Remove a ";" prefix, if present. 
//如果有”;”前缀,则删除 
 set req.http.cookie = regsub(req.http.cookie, "^;s*", ""); 
 // Remove empty cookies. 
// 删除空cookies 
 if (req.http.cookie ~ "^s*$") { 
  unset req.http.cookie; 
 }  
 
 // exclude umjobs and gospelpedia test sites 
// 排除umjos和gospelpedia测试站点 
 if (req.http.host ~ "domain1.org" || req.http.host ~ "domain2.org") { 
  return (pass); 
 } 
 
 // exclude the cron and supercron pages 
// 排除cron和supercron网页 
 if (req.url ~ "cron.php") { 
  return (pass); 
 } 
 // exclude dynamic pages (as did Boost) 
// 排除动态网页(也是提高(处理)) 
 if (req.http.host ~ "domain.org" && req.url ~ "^/(user/login|user/password|user/register|logout|cart|post-blog|site-feedback|cgi-bin/webscr|redirect-home|cv-enroll|recommended-content|node/8755|node/8830|node/8351|node/8757|node/8831|cart/(.*)|uc_paypal/(.*)|civicrm/(.*)|admin/(.*)|recommended-content/(.*)|comment/reply/(.*)|node/add/(.*))" ) { 
  return (pass); 
 } 
 
 // exclude in case of Referer Theme 
// 排除Referer的一些主题 
 if (req.http.host ~ "domain.org" && req.http.referer ~ "www.christianvolunteering.org|worldvision.christianvolunteering.org|ccda.christianvolunteering.org|www.ccda.org|www.urbanresource.net|mobile.urbanministry.org|www.ministeriourbano.com") { 
  return (pass); 
 } 
  
// 修复Moodle规则 
  // Cache Moodle theme files 
//缓存Moodle主题文件 
  if (req.url ~ "/pix/.*.gif$") { 
   return (lookup); 
  } 
 
  // Moodle doesn't like to be cached, passing 
//Moodle主题不能缓存的就pass 
  if (req.http.cookie ~ "(MoodleSession|MoodleSessionTest)") { 
   return (pass); 
  } 
  if (req.http.host == "www.domain.edu" && req.url ~ "^/courses") { 
   return (pass); 
  } 
  if (req.url ~ "file.php") { 
   return (pass); 
  } 
 
  // WPMU themes are not playing well with static file caching 
//WPMU主题使用静态文件缓存运行的不太好 
  if (req.http.host == "domain.org" && req.url ~ "/blogs/(.*)/wp-content/themes") { 
   return (pass); 
  } 
  
  
 
 //删除那些阻止缓存的Set-cookie头 
 // Don't have cookies on static files (gchaix says may cause loss of session; I haven't observed that) 
  if (req.url ~ ".(gif|jpg|swf|css|js|png|jpg|jpeg|gif|png|tiff|tif|svg|swf|ico|doc|ppt|pps|xls|odc|odb|odf|odg|odi|odp|ods|odt|sxc|sxd|sxi|sxw)$") { 
  remove obj.http.Set-cookie; 
 } 
 
 // Don't set session cookie on ChristianVolunteering.org static files or pages that are same for all users 
//对于(头)ChristianVolunteering.org的静态文件和网页,对所有用户不设置session cookie 
  if (req.http.host ~ "christianvolunteering.org" && 
     (req.url ~ "^/$" || 
     req.url ~ "(searchform|advancedsearch|shorttermmissions|recruitvolunteers|volunteergettingstarted|virtualvolunteer|organizationsearch|abs-bible-outreach|ab*ecutive-volunteers|abs-traveling-engagement-center|churchinstructions|sitemap|city|virtual|organizationlistings|orglistings7407|technology|volunteerlistings|forgotpassword|churchvolunteer|churchvolunteering|servicetrip|region|citysitemap|searchformadv|personalitytest|groupvolunteering|disasterreliefvolunteering|disasterrelief|internships|christiangapyear|about|FAQs|bookrecommendations|contact|pressrelease|training|volunteerstart|volunteerstories|articles).jsp$" || 
     req.url ~ "org/org[0-9]+.jsp$" || 
     req.url ~ "org/opp[0-9]+.jsp$" || 
     req.url ~ "orglistings[0-9]+.jsp$" || 
 req.url ~ "org/[^/]+.jsp$" || 
     req.url ~ "volunteer/[^/]+.jsp$") 
    ) {   
  set obj.http.Set-cookie = regsuball(req.http.cookie, "(^|;s*)(JSESSIONID)=[^;]*", ""); 
  // Remove empty set-cookie. 
  if (obj.http.Set-cookie ~ "^s*$") { 
   unset obj.http.Set-cookie; 
  } 
 } 
 
 
 
// If on www.urbanministry.org or static.urbanministry.org, extend TTL by default (pt. 1) 
//对于www.urbanministry.org或static.urbanministry.org,默认情况下扩展TTL 
 if (req.http.host == "www.domain.org" || req.http.host == "static.domain.org") { 
  set obj.http.X-TTL-Extend = "YES"; 
 } 
 
 // If on cityvision.edu, but not in Moodle, or if on blazinggrace.org, but not in forums, or if on techmission.org, change obj.ttl 
//如果主机头是cityvision.edu但是不在Moodle中,或者主机头是blazinggrace.org,但不在forums中,或者主机头是techmission.org,更改obj.ttl 
 if ((req.http.host ~ "domain.edu" && req.url !~ "/courses") || (req.http.host ~ "blazinggrace.org" && req.url !~ "/forums") || (req.http.host ~ "techmission.org")) { 
  set obj.ttl = 7d; 
  set obj.http.X-Extended-TTL = "7d"; 
} 
 
if (obj.status == 404) {  
  set obj.ttl = 1s;  
if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
}  
 
  
 
 if (!obj.cacheable) { 
  set obj.http.X-Cacheable = "NO: Varnish says not cacheable " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 
 // exclude umjobs and gospelpedia test sites 
// 排除umjobs和gospelpedia测试站点 
 if (req.http.host ~ "domain1.org" || req.http.host ~ "domain2.org") { 
  set obj.http.X-Cacheable = "NO: Test domain " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 if (obj.http.Set-cookie) { 
  set obj.http.X-Cacheable = "NO: Set-cookie " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 if (req.http.cookie ~ "DRUPAL_UID|SESS") { 
  set obj.http.X-Cacheable = "NO: Got Session " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 if (obj.http.Cache-Control ~ "private" || obj.http.Cache-Control ~ "no-cache") { 
  set obj.http.X-Cacheable = "NO: Cache-Control set to not cache " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 if (req.url ~ "cron.php") { 
  set obj.http.X-Cacheable = "NO: Cron job " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 if (req.http.host ~ "domain.org" && req.url ~ "^/(user/login|user/password|user/register|logout|cart|post-blog|site-feedback|cgi-bin/webscr|redirect-home|cv-enroll|recommended-content|node/8755|node/8830|node/8351|node/8757|node/8831|cart/(.*)|uc_paypal/(.*)|civicrm/(.*)|admin/(.*)|recommended-content/(.*)|comment/reply/(.*)|node/add/(.*))" ) { 
  set obj.http.X-Cacheable = "NO: Drupal un-cacheable path " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 if (req.http.host ~ "domain.org" && req.http.referer ~ "www.christianvolunteering.org|worldvision.christianvolunteering.org|ccda.christianvolunteering.org|www.ccda.org|www.urbanresource.net|mobile.urbanministry.org|www.ministeriourbano.com") { 
  set obj.http.X-Cacheable = "NO: Referer Theme " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 if (req.request == "POST") { 
  set obj.http.X-Cacheable = "NO: POST request " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 if (req.http.Authorization) { 
  set obj.http.X-Cacheable = "NO: HTTP Authentication " obj.http.X-Cacheable; 
  if (obj.http.X-TTL-Extend) { unset obj.http.X-TTL-Extend; } 
 } 
 
 // extend TTL for urbanministry.org objects (but not panels, views, or quicktabs); invalidation thru varnish.module + um_common.module 
//为urbaministry.org对象扩展TTL(不是面板、视图,或者quicktabs);经过varnish.module + um_common.module失效 
 if((req.http.host == "www.domain.org" || req.http.host == "static.domain.org") && obj.http.X-TTL-Extend == "YES" && !obj.http.X-Cache-Type) { 
  set obj.ttl = 7d; 
  set obj.http.X-Extended-TTL = "7d"; 
 } 
 
} 
sub vcl_deliver { 
# return (deliver); 
 // add cache hit data 
// 增加缓存命中数据 
 if (obj.hits > 0) { 
  // if hit add hit count 
// 如果命中,增加命中数 
  set resp.http.X-Cache = "HIT"; 
  set resp.http.X-Cache-Hits = obj.hits; 
  // set resp.http.X-Cache-Served-URL = "SERVED " obj.http.X-Request-URL; // http headers are apparently not accessible in vcl_deliver 
//在vcl_deliver中http头明显不可访问 
  // set resp.http.X-Cache-TTL = obj.ttl; // string representation not implemented yet (currently on 2.0.5) 
 } 
 else { 
  set resp.http.X-Cache = "MISS"; 
 } 
} 
 
//指定error子程序,对用户有好些 
sub vcl_error { 
if(obj.status == 503) { 
  set obj.http.Content-Type = "text/html; charset=utf-8"; 
  synthetic {" 
 
 
 
  
  "} obj.status " " obj.response {" 
 
  
  Error "} obj.status " " obj.response {" 
  

"} obj.response {"

Sorry we missed you!

We are currently upgrading our websites to serve you better. We should be up again soon.

If you still receive this message 30 minutes from now, please email webmaster@techmission.org.

Guru Meditation:

XID: "} req.xid {"


Served by Varnish cache server "}; return (deliver); } elsif(obj.status == 403) { set obj.http.Content-Type = "text/html; charset=utf-8"; synthetic {" "} obj.status " " obj.response {" Error "} obj.status " " obj.response {"

"} obj.response {"

TechMission Developer Access only

This page is only accessible to our staff. Please visit our main websites www.techmission.org,www.urbanministry.org, and " title="www.christianvolunteering.org. " style="color: rgb(2, 122, 198); font-weight: bold; text-decoration: none; ">www.christianvolunteering.org.

Guru Meditation:

XID: "} req.xid {"


Served by Varnish cache server "}; return (deliver); } else { set obj.http.Content-Type = "text/html; charset=utf-8"; synthetic {" "} obj.status " " obj.response {" Error "} obj.status " " obj.response {"

"} obj.response {"

Guru Meditation:

XID: "} req.xid {"


Served by Varnish cache server "}; return (deliver); } }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/183240.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号