1 # 2 # This is a basic VCL configuration file for varnish. See the vcl(7) 3 # man page for details on VCL syntax and semantics. 4 # 5 # $Id: default.vcl 1424 2007-05-15 19:38:56Z des $ 6 # 7 8 9 #Backends. We run several services. Two have IP-based hosts, the others are normal namevirtualhost. Define backends: 10 11 backend www { 12 set backend.host = "158.36.78.2"; 13 set backend.port = "81"; 14 } 15 16 backend studkat { 17 set backend.host = "158.36.78.84"; 18 set backend.port = "81"; 19 } 20 21 backend localhost { 22 set backend.host = "127.0.0.1"; 23 set backend.port = "81"; 24 } 25 26 sub vcl_hash { 27 if(req.http.host == "www.hio.no" && req.url == "/" && ! req.http.Referer ~ "hio\.no" && client.ip ~ hio) { 28 set req.hash += "hio"; 29 } 30 } 31 32 sub vcl_recv { 33 34 #Want to determine backend first: 35 #First IP4 host 36 if (req.http.host == "studiekatalog.hio.no" || req.http.host == "158.36.78.84" || req.http.host == "[2001:700:700:2:219:b9ff:fee2:85f9]") { 37 set req.backend = studkat; 38 } 39 40 #Second IP4 host 41 elsif (req.http.host ~ "^(www.)?hio.no$" || req.http.host == "158.36.78.2" || req.http.host ~ "(www.)?ouc.no$" || req.http.host == "[2001:700:700:2:219:b9ff:fee2:85f7]") { 42 set req.backend = www; 43 } 44 45 #NameVirtualHosts 46 else { 47 set req.backend = localhost; 48 } 49 50 #Various redirects 51 #Check for internal frontpage load, and rewrite to node 27 if no referer 52 if(req.http.host ~ "^(www.)?hio.no$" && req.url == "/" && ! req.http.Referer ~ "hio\.no" && client.ip ~ hio) { 53 set req.url = "/content/view/full/27"; 54 } 55 56 #Now, our englishspeaking friends, redirect to english page: 57 if(req.http.host ~ "(www.)?ouc.no$" && req.url == "/") { 58 set req.url = "/content/view/full/4563"; 59 } 60 61 #Things we MUST do: 62 #Always cache images, stylesheets and docs. 63 if (req.url ~ "\.(gif|jpg|swf|css|js|pdf|doc|xsl)$") { 64 lookup; 65 } 66 67 #VCL trickery, from varnish.linpro.no 68 #force lookup even when cookies are present 69 if (req.request == "GET" && req.http.cookie) { 70 lookup; 71 } 72 } 73 74 sub vcl_fetch { 75 76 #Remove cookies from responses altogether: 77 remove obj.http.Set-Cookie; 78 79 #Make category searches cache a lot longer 80 if (req.http.host == "studiekatalog.hio.no" && req.url ~ "^/categorysearch/") { 81 set obj.ttl = 14400s; 82 } 83 } 84 85 #ACL for redirect lookup 86 acl hio { 87 "158.36.98.0"/23; 88 "158.36.161.0"/24; 89 "158.36.78.0"/23; 90 "158.36.108.0"/23; 91 "158.36.118.0"/23; 92 "158.36.144.0"/22; 93 "128.39.73.0"/23; 94 "128.39.75.0"/24; 95 "128.39.89.0"/24; 96 #"2001:700:700::"/48; #IPv6 not supported by varnish atm.... :( 97 }