Created
August 27, 2014 17:43
-
-
Save dadreggors/df3a359d372bfe5b5ed1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std; | |
backend default { | |
.host = "127.0.0.1"; | |
.port = "8008"; | |
} | |
backend jira { | |
.host = "127.0.0.1"; | |
.port = "8080"; | |
} | |
backend confluence { | |
.host = "127.0.0.1"; | |
.port = "8090"; | |
} | |
sub vcl_recv { | |
set req.http.X-Forwarded-For = client.ip; | |
# remove unnecessary cookies | |
if (req.http.cookie ~ "JSESSIONID") { | |
std.log("found jsessionid in request, passing to backend server"); | |
return (pass); | |
} else { | |
unset req.http.cookie; | |
} | |
if (req.http.host == "jira.redcoatgames.com") { | |
#You will need the following line only if your backend has multiple virtual host names | |
#set req.http.host = "jira.redcoatgames.com"; | |
set req.backend = jira; | |
std.log("Requested URL: " + req.url); | |
if (req.url~ "^/login.jsp") { | |
error 750 req.url; | |
} | |
} | |
if (req.http.host == "confluence.redcoatgames.com") { | |
#You will need the following line only if your backend has multiple virtual host names | |
#set req.http.host = "confluence.redcoatgames.com"; | |
set req.backend = confluence; | |
if (req.url~ "^/login.action") { | |
error 750 req.url; | |
} | |
return (lookup); | |
} | |
} | |
sub vcl_fetch { | |
if (req.http.cookie ~ "JSESSIONID" || req.request == "POST") { | |
std.log("not removing cookie/passing POST, url " + req.url); | |
return (deliver); | |
} else { | |
# remove all other cookies and prevent backend from setting any | |
std.log("removing cookie in url " + req.url); | |
unset beresp.http.set-cookie; | |
set beresp.ttl = 600s; | |
} | |
if (req.url ~ "^/") { | |
unset beresp.http.set-cookie; | |
} | |
if (beresp.ttl > 0s) { | |
#/* Remove Expires from backend, it's not long enough */ | |
unset beresp.http.expires; | |
#/* Set the clients TTL on this object */ | |
set beresp.http.cache-control = "max-age=900"; | |
#/* Set how long Varnish will keep it */ | |
set beresp.ttl = 1w; | |
#/* marker for vcl_deliver to reset Age: */ | |
set beresp.http.magicmarker = "1"; | |
} | |
} | |
sub vcl_deliver { | |
# send some handy statistics back, useful for checking cache | |
if (obj.hits > 0) { | |
set resp.http.X-Cache-Action = "HIT"; | |
set resp.http.X-Cache-Hits = obj.hits; | |
} else { | |
set resp.http.X-Cache-Action = "MISS"; | |
} | |
if (resp.http.magicmarker) { | |
#/* Remove the magic marker */ | |
unset resp.http.magicmarker; | |
#/* By definition we have a fresh object */ | |
set resp.http.age = "0"; | |
} | |
} | |
sub vcl_error { | |
if (obj.status == 750) { | |
if (obj.response ~ "login.jsp") { | |
set obj.http.Location = "http://jira.redcoatgames.com/login.jsp"; | |
} else if (obj.response ~ "login.action") { | |
set obj.http.Location = "http://confluence.redcoatgames.com/login.action"; | |
} | |
set obj.status = 301; | |
return(deliver); | |
} | |
return (deliver); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment