Last active
September 22, 2015 10:36
-
-
Save wido/40ffb92ea99842c2666b to your computer and use it in GitHub Desktop.
Varnish VCL EU Ceph mirror
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
vcl 4.0; | |
import std; | |
backend download { | |
.host = "download.ceph.com"; | |
.port = "80"; | |
.connect_timeout = 5s; | |
.first_byte_timeout = 5s; | |
.probe = { | |
.timeout = 10s; | |
.interval = 3s; | |
.window = 10; | |
.threshold = 3; | |
.request = | |
"HEAD / HTTP/1.1" | |
"Host: download.ceph.com" | |
"User-Agent: Varnish-health-check" | |
"Connection: close"; | |
} | |
} | |
backend docs { | |
.host = "docs.ceph.com"; | |
.port = "80"; | |
.connect_timeout = 5s; | |
.first_byte_timeout = 5s; | |
.probe = { | |
.timeout = 10s; | |
.interval = 3s; | |
.window = 10; | |
.threshold = 3; | |
.request = | |
"HEAD / HTTP/1.1" | |
"Host: docs.ceph.com" | |
"User-Agent: Varnish-health-check" | |
"Connection: close"; | |
} | |
} | |
backend ceph { | |
.host = "ceph.com"; | |
.port = "80"; | |
.connect_timeout = 5s; | |
.first_byte_timeout = 5s; | |
.probe = { | |
.timeout = 10s; | |
.interval = 3s; | |
.window = 10; | |
.threshold = 3; | |
.request = | |
"HEAD / HTTP/1.1" | |
"Host: ceph.com" | |
"User-Agent: Varnish-health-check" | |
"Connection: close"; | |
} | |
} | |
backend git { | |
.host = "git.ceph.com"; | |
.port = "80"; | |
.connect_timeout = 5s; | |
.first_byte_timeout = 5s; | |
.probe = { | |
.timeout = 10s; | |
.interval = 3s; | |
.window = 10; | |
.threshold = 3; | |
.request = | |
"HEAD / HTTP/1.1" | |
"Host: ceph.com" | |
"User-Agent: Varnish-health-check" | |
"Connection: close"; | |
} | |
} | |
sub vcl_recv { | |
if (req.url ~ "^/debian-" || req.url ~ "^/rpm-") { | |
set req.backend_hint = download; | |
set req.http.host = "download.ceph.com"; | |
} else if (req.url ~ "^/docs") { | |
set req.backend_hint = docs; | |
set req.http.host = "docs.ceph.com"; | |
} else if (req.url ~ "^/git") { | |
set req.backend_hint = git; | |
set req.http.host = "git.ceph.com"; | |
} else { | |
set req.backend_hint = ceph; | |
set req.http.host = "ceph.com"; | |
} | |
if (req.http.Accept-Encoding) { | |
if (req.http.Accept-Encoding ~ "gzip") { | |
set req.http.Accept-Encoding = "gzip"; | |
} else if (req.http.Accept-Encoding ~ "deflate") { | |
set req.http.Accept-Encoding = "deflate"; | |
} else if (req.http.Accept-Encoding ~ "identity") { | |
set req.http.Accept-Encoding = "identity"; | |
} else { | |
unset req.http.Accept-Encoding; | |
} | |
} | |
unset req.http.Cookie; | |
unset req.http.DNT; | |
if (req.method != "GET" && req.method != "HEAD") { | |
return (synth(400, "Bad Request")); | |
} | |
return (hash); | |
} | |
sub vcl_hash { | |
hash_data(req.url); | |
hash_data(req.http.host); | |
return (lookup); | |
} | |
sub vcl_hit { | |
if (obj.ttl >= 0s) { | |
return (deliver); | |
} | |
if (std.healthy(req.backend_hint)) { | |
if (obj.ttl + 10s > 0s) { | |
return (deliver); | |
} | |
} else { | |
if (obj.ttl + obj.grace > 0s) { | |
return (deliver); | |
} | |
} | |
return (fetch); | |
} | |
sub vcl_backend_fetch { | |
set bereq.http.host = "ceph.com"; | |
return (fetch); | |
} | |
sub vcl_backend_response { | |
set beresp.do_stream = true; | |
set beresp.grace = 8h; | |
if (beresp.status >= 500) { | |
set beresp.ttl = 5s; | |
} else { | |
set beresp.ttl = 1h; | |
} | |
set beresp.http.Expires = "" + (now + beresp.ttl); | |
return (deliver); | |
} | |
sub vcl_deliver { | |
if (obj.hits == 0) { | |
set resp.http.X-Cache-Hit = "No"; | |
} else { | |
set resp.http.X-Cache-Hit = "Yes"; | |
set resp.http.X-Cache-Hits = obj.hits; | |
} | |
return (deliver); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment