Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 4.29 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # This is a basic VCL configuration file for varnish.  See the vcl(7)
  2. # man page for details on VCL syntax and semantics.
  3. #
  4. # Default backend definition.  Set this to point to your content
  5. # server.
  6. #
  7. #
  8. # Below is a commented-out copy of the default VCL logic.  If you
  9. # redefine any of these subroutines, the built-in logic will be
  10. # appended to your code.
  11. #
  12.  
  13.  backend ocala {
  14.      .host = "prepstest.ocala.com";
  15.      .port = "80";
  16.  }
  17.  backend lakeland {
  18.       .host = "prepstest.theledger.com";
  19.       .port = "80";
  20.  }
  21. # backend santarosa {
  22. #      .host = "prepstest.pressdemocrat.com";
  23. #      .port = "80";
  24. # }
  25.  
  26.  
  27.  
  28. sub vcl_recv {
  29.  
  30.     if (req.request == "/admin") {
  31.         return (pass);
  32.     }
  33.  
  34.     if (req.http.host == "ocala.com") {
  35.         #You will need the following line only if your backend has multiple virtual host names
  36.         set req.http.host = "prepstest2.ocala.com";
  37.         set req.backend = ocala;
  38.         return (lookup);
  39.     }
  40.     if (req.http.host == "theledger.com") {
  41.         #You will need the following line only if your backend has multiple virtual host names
  42.         set req.http.host = "prepstest2.theledger.com";
  43.         set req.backend = lakeland;
  44.         return (lookup);
  45.     }
  46. #    if (req.http.host == "pressdemocrat.com") {
  47. #        #You will need the following line only if your backend has multiple virtual host names
  48. #        set req.http.host = "prepstest2.pressdemocrat.com";
  49. #        set req.backend = santarosa;
  50. #        return (lookup);
  51. #    }
  52.  
  53.      set req.grace = 1m;
  54.      unset req.http.Cookie;
  55.      unset req.http.Authorization;
  56.  
  57.      if (req.http.x-forwarded-for) {
  58.         set req.http.X-Forwarded-For = req.http.X-Forwarded-For ", " client.ip;
  59.     } else {
  60.         set req.http.X-Forwarded-For = client.ip;
  61.   }
  62.  
  63.  
  64.     if (req.request != "GET" &&
  65.       req.request != "HEAD" &&
  66.       req.request != "PUT" &&
  67.       req.request != "POST" &&
  68.       req.request != "TRACE" &&
  69.       req.request != "OPTIONS" &&
  70.       req.request != "DELETE") {
  71.         #/* Non-RFC2616 or CONNECT which is weird. */
  72.         return (pipe);
  73.     }
  74.     if (req.request != "GET" && req.request != "HEAD") {
  75.         #/* We only deal with GET and HEAD by default */
  76.         return (pass);
  77.     }
  78.     if (req.http.Authorization || req.http.Cookie) {
  79.         #/* Not cacheable by default */
  80.  
  81.     }
  82.     if(req.http.X-No-Cache ~ "YES") {
  83.       return(pass);
  84.    }
  85.  
  86.   if (req.http.Accept-Encoding) {
  87.     if (req.http.Accept-Encoding ~ "gzip") {
  88.       set req.http.Accept-Encoding = "gzip";
  89.     } elsif (req.http.Accept-Encoding ~ "deflate") {
  90.       set req.http.Accept-Encoding = "deflate";
  91.     } else {
  92.       remove req.http.Accept-Encoding;
  93.     }
  94.   }
  95.  
  96.   return (lookup);
  97. }
  98.  
  99. sub vcl_fetch {
  100.  
  101.     if (beresp.http.Cache-Control ~ "(no-cache|no-store|private|must-revalidate)") {
  102.      return(pass);
  103.     }
  104.     if(beresp.status >= 300){
  105.         return (pass);
  106.     }
  107.     if (beresp.ttl < 180s){
  108.         set beresp.ttl = 180s;
  109.     }
  110.     set beresp.grace = 1m;
  111.   remove beresp.http.Via;
  112.   remove req.http.cookie;
  113.   remove beresp.http.Set-Cookie;
  114.     if (req.url ~ "\.(css|js|jpg|jpeg|gif|ico|png)$") {
  115.         unset beresp.http.expires;
  116.         set beresp.http.Cache-Control = "public, max-age=300";
  117.   set beresp.http.age = "0";
  118.   set beresp.http.expires = beresp.ttl;
  119.     } else {
  120.         # set beresp.http.cache-control = "private, max-age=0, must-revalidate";
  121.         # set beresp.http.pragma = "no-cache";
  122.     }
  123.   # only cache successful requests
  124.     return(deliver);
  125. }
  126.  
  127. sub vcl_deliver {
  128.   # This just inserts a diagnostic header to let us know if the content
  129.   # was served via a cache hit, or whether it was a miss.
  130.  
  131.   if (obj.hits > 0) {
  132.     set resp.http.X-Cache = "HIT";
  133.   } else {
  134.    set resp.http.X-Cache = "MISS";
  135.   }
  136.  
  137.     return (deliver);
  138. }
  139.  
  140. sub vcl_error {
  141.     set obj.http.Content-Type = "text/html; charset=utf-8";
  142.     synthetic {"
  143. <?xml version="1.0" encoding="utf-8"?>
  144. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  145.  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  146. <html>
  147.   <head>
  148.     <title>"} obj.status " " obj.response {"</title>
  149.   </head>
  150.   <body>
  151.     <h1>Error "} obj.status " " obj.response {"</h1>
  152.     <p>"} obj.response {"</p>
  153.     <h3>Guru Meditation:</h3>
  154.     <p>XID: "} req.xid {"</p>
  155.     <hr>
  156.     <address>
  157.        <a href="http://www.varnish-cache.org/">Varnish cache server</a>
  158.     </address>
  159.  
  160. </body>
  161. </html>
  162. "};
  163.     return (deliver);
  164. }