backend pic_yourdomain_1 { .host = "1.2.3.4"; .port = "80"; .probe = { .interval = 20s; .timeout = 20s; .window = 5; .threshold = 3; .request = "HEAD / HTTP/1.1" "Host:host.yourdomain.com" "Connection:close"; } } backend pic_yourdomain_2 { .host = "1.2.3.5"; .port = "80"; .probe = { .interval = 20s; .timeout = 20s; .window = 5; .threshold = 3; .request = "HEAD / HTTP/1.1" "Host:host.yourdomain.com" "Connection:close"; } } director pic_yourdomain random { { .backend = pic_yourdomain_1; .weight = 5 ; } { .backend = pic_yourdomain_2; .weight = 5 ; } } acl purge { "localhost"; "127.0.0.1"; "192.168.1.0"/24; "219.239.89.0"/25; "218.241.222.114"; } sub vcl_recv { if (req.http.Accept-Encoding) { if (req.url ~ "(?i)\.(ico|bmp|jpg|png|gif|jpeg|flv|swf)" ) { remove req.http.Accept-Encoding; remove req.http.Cookie; } else if (req.http.Accept-Encoding ~ "(?i)gzip") { set req.http.Accept-Encoding = "gzip"; } else if (req.http.Accept-Encoding ~ "(?i)deflate") { set req.http.Accept-Encoding = "deflate"; } else { remove req.http.Accept-Encoding; } } if (req.url ~ "(?i)\.(jpg|jpeg|png|gif|bmp|css|js|swf|flv|mp3|wmv|wav|avi)($|\?)" ) { if (req.http.referer && !req.http.referer ~ "(yourdomainimages|yourdomain|120ping|fx120|120\.net|iiyi\.com|120sc\.net|aids120|byby120|ruxian120|fkyz120|zhe ngxing999|google|baidu|soso|yahoo|youdao|bing|sohu)" ) { error 404 "not found"; } } if (req.http.host ~ "yourdomain.com") { set req.backend = pic_yourdomain ; } else if(req.http.host ~ "img.yourdomain.com") { set req.backend = pic_yourdomain; } else { error 405 "bad hostname"; } #set client.identity = client.ip ; set req.http.X-Forwarded-For = client.ip ; if (req.backend.healthy) { set req.grace = 10s; } else { set req.grace = 3h; } if (req.request == "PURGE") { if (!client.ip ~ purge) { error 405 "Not Allowed"; } return (lookup); } if (req.request == "GET" && req.url ~ "(?i)\.(jpg|jpeg|png|gif|swf|jpeg|ico|js|css)$") { unset req.http.cookie; } if (req.request != "GET" && req.request != "HEAD" && req.request != "PUT" && req.request != "POST" && req.request != "TRACE" && req.request != "OPTIONS" && req.request != "DELETE") { return (pipe); } if (req.request != "GET" && req.request != "HEAD") { return (pass); } if (req.http.Authorization) { return (pass); } #if (req.request == "GET" && req.url ~ "(?i)\.(jsp|php|asp|aspx)($|\?)") { # return (pass); #} return (lookup); } sub vcl_pipe { return (pipe); } sub vcl_pass { return (pass); } sub vcl_hash { hash_data(req.url); if (req.http.host) { hash_data(req.http.host); } return (hash); } sub vcl_hit { if (req.request == "PURGE") { set obj.ttl = 0s; error 200 "Purged"; } if ( req.http.Pragma ~ "no-cache" && client.ip ~ purge) { set obj.ttl=0s; return (pass); } return (deliver); } sub vcl_miss { if ( req.request == "PURGE" ) { error 404 "not found"; } return (fetch); } sub vcl_fetch { if (beresp.http.Set-Cookie) { return (hit_for_pass); } if (beresp.ttl <= 0s ) { return (hit_for_pass); } if (!beresp.http.Last-Modified) { return (hit_for_pass); } if (beresp.http.Pragma ~ "(?i)no-cache" || beresp.http.Cache-Control ~ "(?i)(no-cache|private)") { return (hit_for_pass); } set beresp.grace = 4h; unset beresp.http.vary; unset beresp.http.Etag; return (deliver); } sub vcl_deliver { if (obj.hits > 0) { set resp.http.Powered-By-Cache = "HIT 5433 " + obj.hits; } else { set resp.http.Powered-By-Cache = "MISS 5433"; } unset resp.http.X-Varnish; unset resp.http.Via; return (deliver); } sub vcl_error { set obj.http.Content-Type = "text/html; charset=utf-8"; set obj.http.Retry-After = "5"; synthetic {" "} + obj.status + " " + obj.response + {"

Error "} + obj.status + " " + obj.response + {"

Guru Meditation:

XID: "} + req.xid + {"


cache server 5433

"}; return (deliver); } sub vcl_init { return (ok); } sub vcl_fini { return (ok); }