From Sagar, 5 Years ago, written in Bash.
Embed
  1. vcl 4.0;
  2. import std;
  3. import directors;
  4.  
  5. backend mfn1 {
  6.     .host = "IP-HIDDEN-1";
  7.     .port = "8080";
  8. }
  9.  
  10. backend mfn2 {
  11.     .host = "IP-HIDDEN-2";
  12.     .port = "8080";
  13. }
  14.  
  15. sub vcl_init {
  16.     new ocean = directors.round_robin();
  17.     ocean.add_backend(mfn1);
  18.     ocean.add_backend(mfn2);
  19. }
  20.  
  21. sub vcl_recv {
  22.  
  23.     set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
  24.     set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
  25.     set req.backend_hint = ocean.backend();
  26.                    
  27.                 if (server.ip == "IP-HIDDEN-1") {
  28.         set req.backend_hint = mfn1;
  29.     } else {
  30.         set req.backend_hint = mfn2;
  31.     }
  32.  
  33.     if(req.url ~ "\.(pdf|woff|eot|svg|ttf|jpeg|jpg|png|gif|ico|swf|js|css|html|htm|xml|php)$") { return (hash); }
  34.  
  35. }
  36.  
  37. #sub vcl_backend_response { set beresp.ttl = 15m; set beresp.grace = 1h; }
  38.  
  39. sub vcl_deliver {
  40. }
  41.  
  42. sub vcl_hash {
  43.     hash_data(server.ip);
  44.     if (req.http.host) {
  45.         hash_data(req.http.host);
  46.     }
  47.     hash_data(req.url);
  48.     if (req.http.Accept-Encoding) {
  49.         hash_data(req.http.Accept-Encoding);
  50.     }
  51.     return (lookup);
  52. }