Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
appnotes:varnishmirror [2009/05/19 10:49] crackerjackmack |
appnotes:varnishmirror [2009/05/21 07:53] (current) crackerjackmack fixed a bug with dead backends |
||
|---|---|---|---|
| Line 24: | Line 24: | ||
| <code C> | <code C> | ||
| backend kernelorg_1 { | backend kernelorg_1 { | ||
| + | #.host = "mirrors.kernel.org"; | ||
| .host = "149.20.20.135"; | .host = "149.20.20.135"; | ||
| - | #.host = "mirrors.kernel.org"; | ||
| .port = "80"; | .port = "80"; | ||
| - | .probe = { | + | .probe = { |
| - | .request = | + | .request = |
| - | "HEAD /index.html HTTP/1.1" | + | "HEAD /index.html HTTP/1.1" |
| - | "Host: mirrors.kernel.org" | + | "Host: mirrors.kernel.org" |
| - | "Connection: close"; | + | "Connection: close"; |
| - | .timeout = 0.3 s; | + | .timeout = 0.3 s; |
| - | .window = 8; | + | .window = 8; |
| - | .threshold = 3; | + | .threshold = 3; |
| - | } | + | } |
| - | } | + | } |
| backend kernelorg_2 { | backend kernelorg_2 { | ||
| Line 53: | Line 53: | ||
| } | } | ||
| + | // A director acts as a router for backends | ||
| director ubuntu random { | director ubuntu random { | ||
| # { .backend = ubuntu_us_1; .weight = 1; } | # { .backend = ubuntu_us_1; .weight = 1; } | ||
| Line 66: | Line 67: | ||
| sub vcl_recv { | sub vcl_recv { | ||
| - | // Skip repository files | + | // BACKEND declarations have to happen first so that dead hosts are |
| + | // properly excluded | ||
| + | |||
| + | // In this case, all these base directories are handled by this single | ||
| + | // backend. It could also look like req.host ~ "linux.etherboot.org" | ||
| + | // for virtual host based setups | ||
| + | if ( req.url ~ "^/(ubuntu|debian|centos|opensuse|suse|fedora|gentoo)" ) { | ||
| + | set req.http.host = "mirrors.kernel.org"; | ||
| + | set req.backend = ubuntu; | ||
| + | } | ||
| + | |||
| + | // Skip repository files (apt) | ||
| if ( req.url ~ "/(Release|Packages|Sources)(|\.gz|\.bz2|\.gpg|)$") { | if ( req.url ~ "/(Release|Packages|Sources)(|\.gz|\.bz2|\.gpg|)$") { | ||
| pass; | pass; | ||
| } | } | ||
| + | // Skip repository files (yum) | ||
| if ( req.url ~ "/repodata/.*" ) { | if ( req.url ~ "/repodata/.*" ) { | ||
| pass; | pass; | ||
| } | } | ||
| - | if ( req.url ~ "^/(ubuntu|debian|centos|opensuse|suse|fedora|gentoo)" ) { | + | |
| - | set req.http.host = "mirrors.kernel.org"; | + | // Basic housekeeping for dead backends |
| - | set req.backend = ubuntu; | + | // Continue serving stale files for up to an hour while the backend recovers |
| - | } | + | |
| if (req.backend.healthy) { | if (req.backend.healthy) { | ||
| set req.grace = 30s; | set req.grace = 30s; | ||
| Line 88: | Line 98: | ||
| sub vcl_fetch { | sub vcl_fetch { | ||
| + | // Debugging info | ||
| set obj.http.X-Varnish-Url = req.url; | set obj.http.X-Varnish-Url = req.url; | ||
| + | |||
| + | // Keep cachable objects up to 1day | ||
| set obj.ttl = 1d; | set obj.ttl = 1d; | ||
| + | // Serve the stale file for up to 15m while a newer version is fetched | ||
| set obj.grace = 15m; | set obj.grace = 15m; | ||
| #set beresp.grace = 15m; | #set beresp.grace = 15m; | ||
| + | // not used yet | ||
| set obj.prefetch = -30s; | set obj.prefetch = -30s; | ||
| } | } | ||
| sub vcl_miss { | sub vcl_miss { | ||
| + | // Nasty spiders!! DIE!! | ||
| if (req.http.user-agent ~ "spider") { | if (req.http.user-agent ~ "spider") { | ||
| error 503 "Not presently in cache, please try again later"; | error 503 "Not presently in cache, please try again later"; | ||
| Line 102: | Line 118: | ||
| sub vcl_deliver { | sub vcl_deliver { | ||
| + | // Debugging headers | ||
| if (obj.hits > 0 ) { | if (obj.hits > 0 ) { | ||
| set resp.http.X-Cache = "HIT"; | set resp.http.X-Cache = "HIT"; | ||