{"id":1205,"date":"2011-07-16T11:46:32","date_gmt":"2011-07-16T15:46:32","guid":{"rendered":"http:\/\/cd34.com\/blog\/?p=1205"},"modified":"2011-07-21T00:19:16","modified_gmt":"2011-07-21T04:19:16","slug":"updated-wordpress-vcl-still-not-complete-but-closer","status":"publish","type":"post","link":"https:\/\/cd34.com\/blog\/infrastructure\/updated-wordpress-vcl-still-not-complete-but-closer\/","title":{"rendered":"Updated WordPress VCL &#8211; still not complete, but, closer"},"content":{"rendered":"<p>Worked with a new client this week and needed to get the VCL working for their installation. They were running W3TC, but, this VCL should work for people running WP-Varnish or any plugin that allows Purging. This VCL is for Varnish 2.x.<\/p>\n<p>There are still some tweaks, but, this appears to be working quite well.<\/p>\n<pre>\r\nbackend default {\r\n    .host = \"127.0.0.1\";\r\n    .port = \"8080\";\r\n}\r\n\r\nacl purge {\r\n    \"10.0.1.100\";\r\n    \"10.0.1.101\";\r\n    \"10.0.1.102\";\r\n    \"10.0.1.103\";\r\n    \"10.0.1.104\";\r\n}\r\n\r\nsub vcl_recv {\r\n if (req.request == \"PURGE\") {\r\n   if (!client.ip ~ purge) {\r\n     error 405 \"Not allowed.\";\r\n   }\r\n   return(lookup);\r\n }\r\n\r\n  if (req.http.Accept-Encoding) {\r\n#revisit this list\r\n    if (req.url ~ \"\\.(gif|jpg|jpeg|swf|flv|mp3|mp4|pdf|ico|png|gz|tgz|bz2)(\\?.*|)$\") {\r\n      remove req.http.Accept-Encoding;\r\n    } elsif (req.http.Accept-Encoding ~ \"gzip\") {\r\n      set req.http.Accept-Encoding = \"gzip\";\r\n    } elsif (req.http.Accept-Encoding ~ \"deflate\") {\r\n      set req.http.Accept-Encoding = \"deflate\";\r\n    } else {\r\n      remove req.http.Accept-Encoding;\r\n    }\r\n  }\r\n  if (req.url ~ \"\\.(gif|jpg|jpeg|swf|css|js|flv|mp3|mp4|pdf|ico|png)(\\?.*|)$\") {\r\n    unset req.http.cookie;\r\n    set req.url = regsub(req.url, \"\\?.*$\", \"\");\r\n  }\r\n  if (req.http.cookie) {\r\n    if (req.http.cookie ~ \"(wordpress_|wp-settings-)\") {\r\n      return(pass);\r\n    } else {\r\n      unset req.http.cookie;\r\n    }\r\n  }\r\n}\r\n\r\nsub vcl_fetch {\r\n# this conditional can probably be left out for most installations\r\n# as it can negatively impact sites without purge support. High\r\n# traffic sites might leave it, but, it will remove the WordPress\r\n# 'bar' at the top and you won't have the post 'edit' functions onscreen.\r\n  if ( (!(req.url ~ \"(wp-(login|admin)|login)\")) || (req.request == \"GET\") ) {\r\n    unset beresp.http.set-cookie;\r\n# If you're not running purge support with a plugin, remove\r\n# this line.\r\n    set beresp.ttl = 5m;\r\n  }\r\n  if (req.url ~ \"\\.(gif|jpg|jpeg|swf|css|js|flv|mp3|mp4|pdf|ico|png)(\\?.*|)$\") {\r\n    set beresp.ttl = 365d;\r\n  }\r\n}\r\n\r\nsub vcl_deliver {\r\n# multi-server webfarm? set a variable here so you can check\r\n# the headers to see which frontend served the request\r\n#   set resp.http.X-Server = \"server-01\";\r\n   if (obj.hits > 0) {\r\n     set resp.http.X-Cache = \"HIT\";\r\n   } else {\r\n     set resp.http.X-Cache = \"MISS\";\r\n   }\r\n}\r\n\r\nsub vcl_hit {\r\n  if (req.request == \"PURGE\") {\r\n    set obj.ttl = 0s;\r\n    error 200 \"OK\";\r\n  }\r\n}\r\n\r\nsub vcl_miss {\r\n  if (req.request == \"PURGE\") {\r\n    error 404 \"Not cached\";\r\n  }\r\n}\r\n<\/pre>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/infrastructure\/updated-wordpress-vcl-still-not-complete-but-closer\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Worked with a new client this week and needed to get the VCL working for their installation. They were running W3TC, but, this VCL should work for people running WP-Varnish or any plugin that allows Purging. This VCL is for Varnish 2.x. There are still some tweaks, but, this appears to be working quite well. [&hellip;]<\/p>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/infrastructure\/updated-wordpress-vcl-still-not-complete-but-closer\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[21,105,26],"class_list":["post-1205","post","type-post","status-publish","format-standard","hentry","category-infrastructure","tag-varnish","tag-vcl","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/comments?post=1205"}],"version-history":[{"count":5,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1205\/revisions"}],"predecessor-version":[{"id":1211,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1205\/revisions\/1211"}],"wp:attachment":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/media?parent=1205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/categories?post=1205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/tags?post=1205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}