From 3e9080e2198e1081daf0e068b92f739233793c3a Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 24 May 2020 14:39:00 +0200 Subject: [PATCH] Initial commit --- tasks/main.yml | 9 ++++++ templates/varnish.vcl.j2 | 63 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tasks/main.yml create mode 100644 templates/varnish.vcl.j2 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..63bc1e1 --- /dev/null +++ b/tasks/main.yml @@ -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 diff --git a/templates/varnish.vcl.j2 b/templates/varnish.vcl.j2 new file mode 100644 index 0000000..5aa6eb7 --- /dev/null +++ b/templates/varnish.vcl.j2 @@ -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); +}