Advertisement
zee123

varnish.vcl

Feb 14th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.62 KB | None | 0 0
  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. backend default {
  8. .host = "127.0.0.1";
  9. .port = "8080";
  10. }
  11. acl purge {
  12. "127.0.0.1";
  13. }
  14. sub vcl_recv {
  15. # Add a unique header containing the client address
  16. remove req.http.X-Forwarded-For;
  17. set    req.http.X-Forwarded-For = client.ip;
  18. # Let's make sure we aren't compressing already compressed formats.
  19. if (req.http.Accept-Encoding) {
  20. if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|mp3|mp4|m4v)(\?.*|)$") {
  21. remove req.http.Accept-Encoding;
  22. } elsif (req.http.Accept-Encoding ~ "gzip") {
  23. set req.http.Accept-Encoding = "gzip";
  24. } elsif (req.http.Accept-Encoding ~ "deflate") {
  25. set req.http.Accept-Encoding = "deflate";
  26. } else {
  27. remove req.http.Accept-Encoding;
  28. }
  29. }
  30. if (req.request == "PURGE") {
  31. if (!client.ip ~ purge) {
  32. error 405 "Not allowed.";
  33. }
  34. return(lookup);
  35. }
  36. if (req.url ~ "^/$") {
  37. unset req.http.cookie;
  38. }
  39. }
  40. sub vcl_hit {
  41. if (req.request == "PURGE") {
  42. set obj.ttl = 0s;
  43. error 200 "Purged.";
  44. }
  45. }
  46. sub vcl_miss {
  47. if (req.request == "PURGE") {
  48. error 404 "Not in cache.";
  49. }
  50. if (!(req.url ~ "wp-(login|admin)")) {
  51. unset req.http.cookie;
  52. }
  53. if (req.url ~ "^/[^?]+.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?.|)$") {
  54. unset req.http.cookie;
  55. set req.url = regsub(req.url, "\?.$", "");
  56. }
  57. if (req.url ~ "^/$") {
  58. unset req.http.cookie;
  59. }
  60. }
  61. sub vcl_fetch {
  62. if (req.url ~ "^/$") {
  63. unset beresp.http.set-cookie;
  64. }
  65. if (!(req.url ~ "wp-(login|admin)")) {
  66. unset beresp.http.set-cookie;
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement