Advertisement
Guest User

Untitled

a guest
Jun 12th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.92 KB | None | 0 0
  1. # This is a basic VCL configuration file for PageCache powered by Varnish for Magento module.
  2.  
  3. # default backend definition. Set this to point to your content server.
  4. backend default {
  5. .host = "127.0.0.1";
  6. .port = "8080";
  7. }
  8.  
  9. # admin backend with longer timeout values. Set this to the same IP & port as your default server.
  10. backend admin {
  11. .host = "127.0.0.1";
  12. .port = "8080";
  13. .first_byte_timeout = 18000s;
  14. .between_bytes_timeout = 18000s;
  15. }
  16.  
  17. # add your Magento server IP to allow purges from the backend
  18. acl purge {
  19. "localhost";
  20. "127.0.0.1";
  21. }
  22.  
  23. import std;
  24.  
  25. sub vcl_recv {
  26. if (req.restarts == 0) {
  27. if (req.http.x-forwarded-for) {
  28. set req.http.X-Forwarded-For =
  29. req.http.X-Forwarded-For + ", " + client.ip;
  30. } else {
  31. set req.http.X-Forwarded-For = client.ip;
  32. }
  33. }
  34.  
  35. if (req.request != "GET" &&
  36. req.request != "HEAD" &&
  37. req.request != "PUT" &&
  38. req.request != "POST" &&
  39. req.request != "TRACE" &&
  40. req.request != "OPTIONS" &&
  41. req.request != "DELETE" &&
  42. req.request != "PURGE") {
  43. /* Non-RFC2616 or CONNECT which is weird. */
  44. return (pipe);
  45. }
  46.  
  47. # purge request
  48. if (req.request == "PURGE") {
  49. if (!client.ip ~ purge) {
  50. error 405 "Not allowed.";
  51. }
  52. ban("obj.http.X-Purge-Host ~ " + req.http.X-Purge-Host + " && obj.http.X-Purge-URL ~ " + req.http.X-Purge-Regex + " && obj.http.Content-Type ~ " + req.http.X-Purge-Content-Type);
  53. error 200 "Purged.";
  54. }
  55.  
  56. # switch to admin backend configuration
  57. if (req.http.cookie ~ "adminhtml=") {
  58. set req.backend = admin;
  59. }
  60.  
  61. # we only deal with GET and HEAD by default
  62. if (req.request != "GET" && req.request != "HEAD") {
  63. return (pass);
  64. }
  65.  
  66. # normalize url in case of leading HTTP scheme and domain
  67. set req.url = regsub(req.url, "^http[s]?://[^/]+", "");
  68.  
  69. # collect all cookies
  70. std.collect(req.http.Cookie);
  71.  
  72. # static files are always cacheable. remove SSL flag and cookie
  73. if (req.url ~ "^/(media|js|skin)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$") {
  74. unset req.http.Https;
  75. unset req.http.Cookie;
  76. }
  77.  
  78. # not cacheable by default
  79. if (req.http.Authorization || req.http.Https) {
  80. return (pass);
  81. }
  82.  
  83. # do not cache any page from index files
  84. if (req.url ~ "^/(index)") {
  85. return (pass);
  86. }
  87.  
  88. # as soon as we have a NO_CACHE cookie pass request
  89. if (req.http.cookie ~ "NO_CACHE=") {
  90. return (pass);
  91. }
  92.  
  93. # remove Google gclid parameters
  94. set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA"
  95. set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar"
  96. set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz"
  97.  
  98. return (lookup);
  99. }
  100.  
  101. # sub vcl_pipe {
  102. # # Note that only the first request to the backend will have
  103. # # X-Forwarded-For set. If you use X-Forwarded-For and want to
  104. # # have it set for all requests, make sure to have:
  105. # # set bereq.http.connection = "close";
  106. # # here. It is not set by default as it might break some broken web
  107. # # applications, like IIS with NTLM authentication.
  108. # return (pipe);
  109. # }
  110. #
  111. # sub vcl_pass {
  112. # return (pass);
  113. # }
  114. #
  115. sub vcl_hash {
  116. hash_data(req.url);
  117. if (req.http.host) {
  118. hash_data(req.http.host);
  119. } else {
  120. hash_data(server.ip);
  121. }
  122.  
  123. if (req.http.cookie ~ "PAGECACHE_ENV=") {
  124. set req.http.pageCacheEnv = regsub(
  125. req.http.cookie,
  126. "(.*)PAGECACHE-env=([^&]*)(.*)",
  127. "\2"
  128. );
  129. hash_data(req.http.pageCacheEnv);
  130. remove req.http.pageCacheEnv;
  131. }
  132.  
  133. if (!(req.url ~ "^/(media|js|skin)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$")) {
  134. call design_exception;
  135. }
  136. return (hash);
  137. }
  138. #
  139. # sub vcl_hit {
  140. # return (deliver);
  141. # }
  142. #
  143. # sub vcl_miss {
  144. # return (fetch);
  145. # }
  146.  
  147. sub vcl_fetch {
  148. if (beresp.status == 500) {
  149. set beresp.saintmode = 10s;
  150. return (restart);
  151. }
  152. set beresp.grace = 5m;
  153.  
  154. # enable ESI feature if needed
  155. if (beresp.http.X-Cache-DoEsi == "1") {
  156. set beresp.do_esi = true;
  157. }
  158.  
  159. # add ban-lurker tags to object
  160. set beresp.http.X-Purge-URL = req.url;
  161. set beresp.http.X-Purge-Host = req.http.host;
  162.  
  163. if (beresp.status == 200 || beresp.status == 301 || beresp.status == 404) {
  164. if (beresp.http.Content-Type ~ "text/html" || beresp.http.Content-Type ~ "text/xml") {
  165. if ((beresp.http.Set-Cookie ~ "NO_CACHE=") || (beresp.ttl < 1s)) {
  166. set beresp.ttl = 0s;
  167. return (hit_for_pass);
  168. }
  169.  
  170. # marker for vcl_deliver to reset Age:
  171. set beresp.http.magicmarker = "1";
  172.  
  173. # Don't cache cookies
  174. unset beresp.http.set-cookie;
  175. } else {
  176. # set default TTL value for static content
  177. set beresp.ttl = 4h;
  178. }
  179. return (deliver);
  180. }
  181.  
  182. return (hit_for_pass);
  183. }
  184.  
  185. sub vcl_deliver {
  186. # debug info
  187. if (resp.http.X-Cache-Debug) {
  188. if (obj.hits > 0) {
  189. set resp.http.X-Cache = "HIT";
  190. set resp.http.X-Cache-Hits = obj.hits;
  191. } else {
  192. set resp.http.X-Cache = "MISS";
  193. }
  194. set resp.http.X-Cache-Expires = resp.http.Expires;
  195. } else {
  196. # remove Varnish/proxy header
  197. remove resp.http.X-Varnish;
  198. remove resp.http.Via;
  199. remove resp.http.Age;
  200. remove resp.http.X-Purge-URL;
  201. remove resp.http.X-Purge-Host;
  202. }
  203.  
  204. if (resp.http.magicmarker) {
  205. # Remove the magic marker
  206. unset resp.http.magicmarker;
  207.  
  208. set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
  209. set resp.http.Pragma = "no-cache";
  210. set resp.http.Expires = "Mon, 31 Mar 2008 10:00:00 GMT";
  211. set resp.http.Age = "0";
  212. }
  213. }
  214.  
  215. # sub vcl_error {
  216. # set obj.http.Content-Type = "text/html; charset=utf-8";
  217. # set obj.http.Retry-After = "5";
  218. # synthetic {"
  219. # <?xml version="1.0" encoding="utf-8"?>
  220. # <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  221. # "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  222. # <html>
  223. # <head>
  224. # <title>"} + obj.status + " " + obj.response + {"</title>
  225. # </head>
  226. # <body>
  227. # <h1>Error "} + obj.status + " " + obj.response + {"</h1>
  228. # <p>"} + obj.response + {"</p>
  229. # <h3>Guru Meditation:</h3>
  230. # <p>XID: "} + req.xid + {"</p>
  231. # <hr>
  232. # <p>Varnish cache server</p>
  233. # </body>
  234. # </html>
  235. # "};
  236. # return (deliver);
  237. # }
  238. #
  239. # sub vcl_init {
  240. # return (ok);
  241. # }
  242. #
  243. # sub vcl_fini {
  244. # return (ok);
  245. # }
  246.  
  247. sub design_exception {
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement