varnish-sample-config.vcl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. backend default {
  2. .host = "127.0.0.1";
  3. .port = "8080";
  4. }
  5. acl purge {
  6. # Web server with plugin which will issue PURGE requests
  7. "localhost";
  8. }
  9. sub vcl_recv {
  10. if (req.request == "PURGE") {
  11. if (!client.ip ~ purge) {
  12. error 405 "Not allowed.";
  13. }
  14. ban("req.url ~ ^" + req.url + "$ && req.http.host == " + req.http.host);
  15. }
  16. # Normalize content-encoding
  17. if (req.http.Accept-Encoding) {
  18. if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|lzma|tbz)(\?.*|)$") {
  19. remove req.http.Accept-Encoding;
  20. } elsif (req.http.Accept-Encoding ~ "gzip") {
  21. set req.http.Accept-Encoding = "gzip";
  22. } elsif (req.http.Accept-Encoding ~ "deflate") {
  23. set req.http.Accept-Encoding = "deflate";
  24. } else {
  25. remove req.http.Accept-Encoding;
  26. }
  27. }
  28. # Remove cookies and query string for real static files
  29. if (req.url ~ "\.(bz2|css|flv|gif|gz|ico|jpeg|jpg|js|lzma|mp3|mp4|pdf|png|swf|tbz|tgz|txt|zip)(\?.*|)$") {
  30. unset req.http.cookie;
  31. set req.url = regsub(req.url, "\?.*$", "");
  32. }
  33. if (req.url ~ "wp-(login|admin|comments-post.php|cron.php)" ||
  34. req.url ~ "preview=true" ||
  35. req.url ~ "xmlrpc.php") {
  36. return (pass);
  37. }
  38. return (lookup);
  39. }
  40. sub vcl_fetch {
  41. # Don't cache backend
  42. if (req.url ~ "wp-(login|admin|comments-post.php|cron.php)" ||
  43. req.url ~ "preview=true" ||
  44. req.url ~ "xmlrpc.php") {
  45. # Dont modify anything, it's (pass) object
  46. } else {
  47. unset beresp.http.set-cookie;
  48. if (beresp.status == 307) {
  49. # Don't cache temporary redirects like ?repeat=w3tc
  50. set beresp.ttl = 0h;
  51. } else if (req.url ~ "\.(bz2|css|flv|gif|gz|ico|jpeg|jpg|js|lzma|mp3|mp4|pdf|png|swf|tbz|tgz|txt|zip)$") {
  52. set beresp.ttl = 30d;
  53. } else {
  54. set beresp.ttl = 4h;
  55. }
  56. }
  57. }
  58. sub vcl_hit {
  59. if (req.request == "PURGE") {
  60. purge;
  61. error 200 "Purged.";
  62. }
  63. }
  64. sub vcl_miss {
  65. if (req.request == "PURGE") {
  66. purge;
  67. error 200 "Purged.";
  68. }
  69. }