This repository has been archived on 2020-08-09. You can view files and clone it, but cannot push or open issues or pull requests.
ansible-varnish/templates/varnish.vcl.j2

75 lines
1.7 KiB
Django/Jinja

vcl 4.1;
import std;
backend default {
.path = "{{ varnish.backend.sock }}";
.max_connections = 300;
.first_byte_timeout = 240s;
.connect_timeout = 10s;
.between_bytes_timeout = 2s;
}
sub vcl_recv {
unset req.http.user-agent;
if ( req.method != "GET" &&
req.method != "HEAD" &&
req.method != "PUT" &&
req.method != "POST" &&
req.method != "TRACE" &&
req.method != "OPTIONS" &&
req.method != "PATCH" &&
req.method != "DELETE") {
return (pipe);
}
if (req.method == "GET" || req.method == "HEAD") {
return (hash);
}
return (pass);
}
sub vcl_hash {
hash_data(req.url);
hash_data(req.http.host);
if (req.http.cookie) {
hash_data(req.http.cookie);
}
if (req.http.authorization) {
hash_data(req.http.authorization);
}
return (lookup);
}
sub vcl_backend_response {
set beresp.do_stream = false;
if ( beresp.http.Set-Cookie ||
beresp.http.Cache-Control ~ "no-cache|no-store|private") {
set beresp.uncacheable = true;
return(deliver);
}
set beresp.grace = 5m;
if (beresp.http.ETag || beresp.http.Last-Modified) {
set beresp.keep = 4h;
}
if (beresp.status == 301) {
set beresp.ttl = 24h;
}
if ( bereq.http.Host == "redxen.eu" ||
beresp.http.Cache-Control ~ "public" ||
beresp.http.Content-Type ~ "text/css" ||
beresp.http.Content-Type ~ "text/javascript" ||
beresp.http.Content-Type ~ "image" ||
beresp.http.Content-Type ~ "video" ||
beresp.http.Content-Type ~ "audio" ||
beresp.http.Content-Type ~ "font") {
set beresp.do_gzip = true;
return (deliver);
}
set beresp.uncacheable = true;
return (deliver);
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
return (deliver);
}