Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. backend default {
  2.     .host = "{string hostname or ip_address}"; #if you don't know, this reads 'localhost'
  3.     .port = "{int port_its_running_on}"; #you set this in httpd.conf
  4. }
  5.  
  6. acl purge { /*set some servers to be authorized to clear the cache*/
  7.     "{string hostname or ip_address}"; #if you don't know, this reads 'localhost'
  8. }
  9.  
  10. sub vcl_recv {
  11.     set req.grace = 6h;
  12.  
  13.     if (req.request == "PURGE") {
  14.         if(!client.ip ~ purge) {
  15.             error 405 "Not allowed.";
  16.         }
  17.  
  18.         purge("req.url ~ ^" req.url "$ && req.http.host == "req.http.host);
  19.     }
  20.  
  21.     if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|lzma|tbz)(\?.*|)$") {
  22.         remove req.http.Accept-Encoding;
  23.     } elsif (req.http.Accept-Encoding ~ "gzip") {
  24.         set req.http.Accept-Encoding = "gzip";
  25.     } elsif (req.http.Accept-Encoding ~ "deflate") {
  26.         set req.http.Accept-Encoding = "deflate";
  27.     } else {
  28.         remove req.http.Accept-Encoding;
  29.     }
  30.  
  31.     if ( (req.url ~ "wp-(login|admin)") || (req.http.Cookie ~ "wordpress_logged_in_") || (req.http.Cookie ~ "comment_author") || (req.url ~ "piwik") ) {
  32.         return (pass);
  33.     }
  34.  
  35.     if (req.request != "GET" && req.request != "HEAD") {
  36.         return (pass);
  37.     }
  38.  
  39.     unset req.http.cookie;
  40.  
  41.     if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|pls|torrent)(\?.*|)$") {
  42.         unset req.http.Authenticate;
  43.         unset req.http.POSTDATA;
  44.         set req.request = "GET";
  45.         set req.url = regsub(req.url, "\?.*$", "");
  46.     }
  47. }
  48.  
  49. sub vcl_pipe {
  50.     set bereq.http.connection = "close";
  51.  
  52.     if (req.http.X-Forwarded-For) {
  53.         set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For;
  54.     } else {
  55.         set bereq.http.X-Forwarded-For = regsub(client.ip, ":.*", "");
  56.     }
  57. }
  58.  
  59. sub vcl_pass {
  60.     set bereq.http.connection = "close";
  61.  
  62.     if (req.http.X-Forwarded-For) {
  63.         set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For;
  64.     } else {
  65.         set bereq.http.X-Forwarded-For = regsub(client.ip, ":.*", "");
  66.     }
  67. }
  68.  
  69. sub vcl_fetch {
  70.     set beresp.ttl = 1h;
  71.     set req.grace = 6h;
  72.  
  73.     if ( (req.url ~ "wp-(login|admin)") || (req.http.Cookie ~ "wordpress_logged_in_") || (req.http.Cookie ~ "comment_author") || (req.url ~ "piwik") ) {
  74.         return (pass);
  75.     }
  76.  
  77.     unset beresp.http.set-cookie;
  78.  
  79.     if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|pls|torrent)$") {
  80.         set beresp.ttl = 24h;
  81.     }
  82. }
  83.  
  84. sub vcl_deliver {
  85.     if (obj.hits > 0) {
  86.         set resp.http.X-Cache = "HIT";
  87.         set resp.http.X-Cache-Hits = obj.hits;
  88.     } else {
  89.         set resp.http.X-Cache = "MISS";
  90.     }
  91. }