Initial commit

This commit is contained in:
Alex 2020-05-24 14:39:00 +02:00
commit 3e9080e219
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 72 additions and 0 deletions

9
tasks/main.yml Normal file
View File

@ -0,0 +1,9 @@
- name: Copy Varnish configuration
template:
follow: yes
src: 'varnish.vcl.j2'
dest: /etc/varnish/default.vcl
notify: Run service actions
tags:
- varnish
- configs

63
templates/varnish.vcl.j2 Normal file
View File

@ -0,0 +1,63 @@
vcl 4.1;
backend default {
.path = "{{ varnish.backend.sock }}";
.max_connections = 300;
.first_byte_timeout = 240s;
.connect_timeout = 10s;
.between_bytes_timeout = 2s;
}
sub vcl_recv {
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.http.Upgrade ~ "(?i)websocket") {
return (pipe);
}
if (req.http.Range) {
return (pass);
}
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);
}
return (lookup);
}
sub vcl_hit {
return (deliver);
}
sub vcl_miss {
return (fetch);
}
sub vcl_pipe {
if (req.http.upgrade) {
set bereq.http.upgrade = req.http.upgrade;
}
return (pipe);
}
sub vcl_backend_response {
if (beresp.status == 500 || beresp.status == 502 || beresp.status == 503 || beresp.status == 504) {
return (abandon);
}
if (beresp.http.Cache-Control ~ "public") {
return (deliver);
}
if (beresp.status == 301) {
return(deliver);
}
return (pass);
}