From 6d04fd847b8af520cbd6f7e75cac86cc5ff317d8 Mon Sep 17 00:00:00 2001 From: zhongjin Date: Thu, 11 May 2023 13:10:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'config/varnish.vcl'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/varnish.vcl | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 config/varnish.vcl diff --git a/config/varnish.vcl b/config/varnish.vcl new file mode 100644 index 0000000..88f62a3 --- /dev/null +++ b/config/varnish.vcl @@ -0,0 +1,49 @@ +acl purge { + "localhost"; + "127.0.0.1"; +} + +backend sqlapi { + .host = "127.0.0.1"; + .port = "8080"; +} + +backend windshaft { + .host = "127.0.0.1"; + .port = "8181"; +} + +sub vcl_recv { + # Allowing PURGE from localhost + if (req.request == "PURGE") { + if (!client.ip ~ purge) { + error 405 "Not allowed."; + } + return (lookup); + } + + # Routing request to backend based on X-Carto-Service header from nginx + if (req.http.X-Carto-Service == "sqlapi") { + set req.backend = sqlapi; + remove req.http.X-Carto-Service; + } + if (req.http.X-Carto-Service == "windshaft") { + set req.backend = windshaft; + remove req.http.X-Carto-Service; + } +} + +sub vcl_hit { + if (req.request == "PURGE") { + purge; + error 200 "Purged."; + } +} + +sub vcl_miss { + if (req.request == "PURGE") { + purge; + error 200 "Purged."; + } +} +Footer