Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- backend local {
- .host = "127.0.0.1";
- .port = "17000";
- }
- # TODO put health checks in the backends to check the
- # SI VIPs to move traffic away from a bad VIP
- director thermos round-robin {
- { .backend = {
- .host = "208.x.x.x";
- .port = "80";
- }
- }
- { .backend = {
- .host = "208.x.x.x";
- .port = "80";
- }
- }
- }
- acl purge {
- "38.x.x.0"/24;
- "208.x.x.0"/24;
- "10.101.0.0"/16;
- "localhost";
- }
- sub vcl_recv {
- set req.backend = thermos;
- # if (req.restarts == 0) {
- # }
- # so infuriating!!
- if (req.url ~ "^http://") {
- set req.url = regsub(req.url, "http://[^/]*", "");
- }
- # MUCHO IMPORTANTE
- # http://varnish-cache.org/wiki/FAQ/Compression
- if (req.http.Accept-Encoding) {
- if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$" || req.url ~ ".*scaled.php.*" ) {
- # No point in compressing these
- remove req.http.Accept-Encoding;
- } elsif (req.http.Accept-Encoding ~ "gzip") {
- set req.http.Accept-Encoding = "gzip";
- } elsif (req.http.Accept-Encoding ~ "deflate") {
- set req.http.Accept-Encoding = "deflate";
- } else {
- # unkown encoding
- remove req.http.Accept-Encoding;
- }
- }
- if (req.url ~ ".*scaled\.php.*server=&.*") {
- error 400 "Bad Request";
- }
- if (req.request != "GET" && req.request != "HEAD") {
- # PURGE request if zope asks nicely
- if (req.request == "PURGE") {
- if (!client.ip ~ purge) {
- error 405 "Not allowed.";
- }
- return(lookup);
- }
- return(pipe);
- }
- if (req.http.Expect) {
- return(pipe);
- }
- if (req.http.Authenticate || req.http.Authorization) {
- return(pass);
- }
- # We only care about the "__ac.*" cookies, used for authentication
- if (req.http.Cookie && req.http.Cookie ~ "__ac(|_(name|password|persistent))=") {
- return(pass);
- }
- if (req.url ~ "^/healthz") {
- error 204 "health OK";
- }
- # File type that we will always cache
- if (req.request == "GET" && req.url ~ "\.(gif|jpg|swf|css|js|png|jpg|jpeg|gif|png|tiff|tif|svg|swf|ico|css|js|vsd|doc|ppt|pps|xls|pdf|mp3|mp4|m4a|ogg|mov|avi|wmv|sxw|zip|gz|bz2|tgz|tar|rar|odc|odb|odf|odg|odi|odp|ods|odt|sxc|sxd|sxi|sxw|dmg|torrent|deb|msi|iso|rpm)$") {
- return(lookup);
- }
- # normalize req.url to cut down on dups
- if (req.url ~ "^/+img[0-9]{1,4}/[0-9]{1,4}/.*\?.*$") {
- set req.url = regsub(req.url, "\?.*", "");
- }
- if (req.request == "POST") {
- error 405 "Method Not Allowed";
- }
- # force return(lookup) even when cookies are present
- if (req.request == "GET" && req.http.cookie) {
- return(lookup);
- }
- return(lookup);
- }
- sub vcl_fetch {
- if (beresp.http.Set-Cookie) {
- unset beresp.http.Set-Cookie;
- }
- # force minimum ttl
- if (beresp.cacheable) {
- set beresp.ttl = 6h;
- /* Remove Expires from backend, it's not long enough */
- unset beresp.http.expires;
- /* Set how long Varnish will keep it */
- /* marker for vcl_deliver to reset Age: */
- set beresp.http.magicmarker = "1";
- }
- remove beresp.http.X-Varnish-IP;
- remove beresp.http.X-Varnish-Port;
- }
- sub vcl_hit {
- # Do the PURGE thing
- if (req.request == "PURGE") {
- set obj.ttl = 0s;
- error 200 "Purged";
- } else {
- set obj.ttl = 12h;
- }
- }
- sub vcl_miss {
- if (req.request == "PURGE") {
- error 404 "Not in cache";
- }
- set bereq.http.host = "desmondweb.<domain>.us";
- set bereq.http.X-Thermos-L7-Switch-Server-Type = "desmond_web";
- }
- sub vcl_hash {
- set req.hash += req.url;
- return(hash);
- }
- sub vcl_deliver {
- if (resp.http.magicmarker) {
- /* Remove the magic marker */
- unset resp.http.magicmarker;
- /* By definition we have a fresh object */
- set resp.http.age = "0";
- }
- set resp.http.X-Varnish-Hits = obj.hits;
- set resp.http.X-Varnish-IP = server.ip;
- set resp.http.X-Varnish-Port = server.port;
- return(deliver);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement