Advertisement
Guest User

Untitled

a guest
Jan 1st, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #
  2. # This is an example VCL file for Varnish.
  3. #
  4. # It does not do anything by default, delegating control to the
  5. # builtin VCL. The builtin VCL is called when there is no explicit
  6. # return statement.
  7. #
  8. # See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
  9. # and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples.
  10.  
  11. # Marker to tell the VCL compiler that this VCL has been adapted to the
  12. # new 4.0 format.
  13. vcl 4.0;
  14.  
  15. # Default backend definition. Set this to point to your content server.
  16. backend default {
  17. .host = "127.0.0.1";
  18. .port = "81";
  19. }
  20. backend onedomain {
  21. .host = "127.0.0.1";
  22. .port = "81";
  23. }
  24. backend newdomain {
  25. .host = "127.0.0.1";
  26. .port = "81";
  27. }
  28.  
  29. acl purge {
  30. "localhost";
  31. }
  32.  
  33. sub vcl_recv {
  34. # Happens before we check if we have this in cache already.
  35. #
  36. # Typically you clean up the request here, removing cookies you don't need,
  37. # rewriting the request, etc.
  38.  
  39. #Bypass large files
  40. if (req.http.x-pipe-mark && req.restarts > 0) {
  41. return(pipe);
  42. }
  43.  
  44. # all domains in here will return a "pass" which means they won't be cached
  45. if (req.http.host ~ "(www\.)?(domain1.com|domain2.com)") {
  46. return (pass);
  47. }
  48. #else check if something we're going to cache
  49. else if(req.http.host ~ "(www\.)?(onedomain.nu)") {
  50. set req.http.host = "onedomain.com";
  51. set req.backend_hint = onedomain;
  52. }
  53. else if(req.http.host ~ "(www\.)?(newdomain.com)") {
  54. set req.http.host = "newdomain.com";
  55. set req.backend_hint = newdomain;
  56. }
  57. else {
  58. return (pass);
  59. }
  60.  
  61. if (req.method == "PURGE") {
  62. if (client.ip !~ purge) {
  63. return (synth(405));
  64. }
  65. if (req.http.X-Purge-Method == "regex") {
  66. ban("req.url ~ " + req.url + " && req.http.host ~ " + req.http.host);
  67. return (synth(200, "Banned."));
  68. }
  69. else {
  70. return (purge);
  71. }
  72. }
  73. #Drop cookies
  74. set req.http.cookie = regsuball(req.http.cookie, "wp-settings-\d+=[^;]+(; )?", "");
  75. set req.http.cookie = regsuball(req.http.cookie, "wp-settings-time-\d+=[^;]+(; )?", "");
  76. set req.http.cookie = regsuball(req.http.cookie, "wordpress_test_cookie=[^;]+(; )?", "");
  77. if (req.http.cookie == "") {
  78. unset req.http.cookie;
  79. }
  80.  
  81. #Handle admin login
  82. if (req.url ~ "wp-admin|wp-login") {
  83. return (pass);
  84. }
  85. }
  86.  
  87. sub vcl_backend_response {
  88. # Happens after we have read the response headers from the backend.
  89. #
  90. # Here you clean the response headers, removing silly Set-Cookie headers
  91. # and other mistakes your backend does.
  92. }
  93.  
  94. sub vcl_deliver {
  95. # Happens when we have all the pieces we need, and are about to send the
  96. # response to the client.
  97. #
  98. # You can do accounting or modifying the final object here.
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement