Created
May 13, 2011 06:48
-
-
Save jnlin/970095 to your computer and use it in GitHub Desktop.
VCL file
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
backend static1 { | |
.host = "10.1.1.85"; | |
.port = "81"; | |
.probe = { | |
.request = | |
"GET /robots.txt?healthcheck=varnish&monitor=Monitor_s.pixfs.net HTTP/1.1" | |
"Host: s.pixfs.net" | |
"Connection: close"; | |
.interval = 5 s; | |
.timeout = 2 s; | |
.window = 1; | |
.threshold = 1; | |
} | |
} | |
backend static2 { | |
.host = "10.1.1.219"; | |
.port = "81"; | |
.probe = { | |
.request = | |
"GET /robots.txt?healthcheck=varnish&monitor=Monitor_s.pixfs.net HTTP/1.1" | |
"Host: s.pixfs.net" | |
"Connection: close"; | |
.interval = 5 s; | |
.timeout = 2 s; | |
.window = 1; | |
.threshold = 1; | |
} | |
} | |
backend static3 { | |
.host = "10.1.1.215"; | |
.port = "81"; | |
.probe = { | |
.request = | |
"GET /robots.txt?healthcheck=varnish&monitor=Monitor_s.pixfs.net HTTP/1.1" | |
"Host: s.pixfs.net" | |
"Connection: close"; | |
.interval = 5 s; | |
.timeout = 2 s; | |
.window = 1; | |
.threshold = 1; | |
} | |
} | |
director static round-robin { | |
{ .backend = static1; } | |
{ .backend = static2; } | |
{ .backend = static3; } | |
} | |
acl purge { | |
"localhost"; | |
"10.0.0.0"/8; | |
} | |
sub vcl_recv { | |
if (req.http.host ~ "^s.pixfs.net$" || req.http.host ~ "^css.pixnet.in$" || req.http.host ~ "^s.pimg.tw$") { | |
set req.backend = static; | |
} | |
if (req.request == "GET") { | |
return(lookup); | |
} | |
if (req.request == "PURGE") { | |
if (!client.ip ~ purge) { | |
error 403 "Forbidden"; | |
} | |
return(lookup); | |
} | |
return(lookup); | |
} | |
sub vcl_hit { | |
if (req.request == "PURGE") { | |
set obj.ttl = 0s; | |
error 200 "Purged"; | |
} | |
return(deliver); | |
} | |
sub vcl_miss { | |
if (req.request == "PURGE") { | |
error 404 "Not Found"; | |
} | |
} | |
sub vcl_fetch { | |
# max_restarts defaults to 4. | |
if (beresp.status != 200 && beresp.status != 204 | |
&& beresp.status != 403 && beresp.status != 404 | |
&& beresp.status != 301 && beresp.status != 302) { | |
return(restart); | |
} | |
if (beresp.status >= 400) { | |
set beresp.ttl = 0s; | |
} | |
if (req.request == "HEAD") { | |
set beresp.http.head = "yes"; | |
} | |
set beresp.http.X-Cacheable = "YES"; | |
if (req.url ~ "\.(css|js|html|htm|xml|txt)$") { | |
set beresp.do_gzip = true; | |
} | |
return(deliver); | |
} | |
sub vcl_deliver { | |
set resp.http.X-Served-By = server.hostname; | |
if (obj.hits > 0) { | |
set resp.http.X-Cache = "HIT"; | |
set resp.http.X-Cache-Hits = obj.hits; | |
} else { | |
set resp.http.X-Cache = "MISS"; | |
} | |
return(deliver); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment