Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- backend web01 {
- .host = "192.168.30.101";
- .port = "80";
- .connect_timeout = 1s;
- .first_byte_timeout = 5s;
- .probe = {
- .url = "/";
- .timeout = 10s;
- .interval = 30s;
- .window = 2;
- .threshold = 2;
- }
- }
- backend web02 {
- .host = "192.168.30.102";
- .port = "80";
- .connect_timeout = 1s;
- .first_byte_timeout = 5s;
- .probe = {
- .url = "/";
- .timeout = 10s;
- .interval = 30s;
- .window = 2;
- .threshold = 2;
- }
- }
- backend web03 {
- .host = "192.168.30.103";
- .port = "80";
- .connect_timeout = 1s;
- .first_byte_timeout = 5s;
- .probe = {
- .url = "/";
- .timeout = 10s;
- .interval = 30s;
- .window = 2;
- .threshold = 2;
- }
- }
- director web_cluster round-robin {
- { .backend = web01; }
- { .backend = web02; }
- { .backend = web03; }
- }
- #deflate logic ~ call normalize_deflate;
- sub normalize_deflate {
- if (req.http.Accept-Encoding) {
- if (req.http.Accept-Encoding ~ "gzip") {
- set req.http.Accept-Encoding = "gzip";
- }
- elsif (req.http.Accept-Encoding ~ "deflate") {
- set req.http.Accept-Encoding = "deflate";
- }
- else {
- remove req.http.Accept-Encoding;
- }
- }
- }
- #normalize request to be cached ~ call recv_cache_prep;
- sub recv_cache_prep {
- unset req.http.cookie;
- unset req.http.user-agent;
- return(lookup);
- }
- #normalize response to be cached ~ call fetch_cache_prep;
- sub fetch_cache_prep {
- unset beresp.http.last-modified;
- unset beresp.http.set-cookie;
- unset beresp.http.expires;
- unset beresp.http.etag;
- set beresp.http.cache-control = "max-age = 3600";
- }
- #set our objects to brand new and add our X-cache header
- sub vcl_deliver {
- set resp.http.age = "0";
- if (obj.hits > 0) {
- set resp.http.X-Cache = "m: HIT " obj.hits;
- }
- else {
- set resp.http.X-Cache = "m: MISS";
- }
- }
- #restart if we can't get a valid response
- sub vcl_error {
- if (obj.status == 503 && req.restarts >= 5) {
- restart;
- }
- }
- sub vcl_recv {
- set req.http.X-Forwarded-For = client.ip;
- #misc settings
- set req.grace = 1h;
- #deflate logic
- call normalize_deflate;
- #set our backend
- set req.backend = web_cluster;
- #static files
- if (req.url ~ "^/[^?]+\.((?i)bmp|jpeg|jpg|png|gif|ico|js|css|txt|zip|swf|pdf)(\?.*|)$") {
- set req.url = regsub(req.url, "\?.*$", "");
- set req.http.X-v_cache = "file";
- call recv_cache_prep;
- }
- #no caching
- else {
- unset req.http.if-modified-since;
- return(pass);
- }
- }
- sub vcl_fetch {
- #misc settings
- set beresp.grace = 1h;
- #static file
- if (req.http.X-v_cache == "file") {
- call fetch_cache_prep;
- set beresp.ttl = 12h;
- }
- #don't cache 404's or redirects
- elsif (beresp.status == 404 || beresp.status == 302 || beresp.status == 301) {
- set beresp.cacheable = false;
- return(pass);
- }
- #no caching
- else {
- set beresp.cacheable = false;
- return(pass);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement