From 703f52c217c38c66978e84500a28f23073c1a68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l-Kristian=20Hamre?= Date: Thu, 31 Jul 2025 00:15:51 +0200 Subject: [PATCH] Update info. --- config/varnish/default.vcl | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/config/varnish/default.vcl b/config/varnish/default.vcl index 16c8000..915b486 100644 --- a/config/varnish/default.vcl +++ b/config/varnish/default.vcl @@ -2,9 +2,6 @@ vcl 4.1; # https://github.com/varnish/toolbox/tree/master/vcls/hit-miss include "hit-miss.vcl"; - -# import vmod_dynamic for better backend name resolution -import dynamic; import std; backend default { @@ -19,6 +16,12 @@ acl purge { } sub vcl_recv { + set req.http.Host = regsub(req.http.Host, ":[0-9]+", ""); + unset req.http.proxy; + set req.url = std.querysort(req.url); + set req.url = regsub(req.url, "\?$", ""); + set req.http.Surrogate-Capability = "key=ESI/1.0"; + if (req.url ~ "/purge-cache") { if (!client.ip ~ purge) { return(synth(403, "Not allowed.")); @@ -26,9 +29,17 @@ sub vcl_recv { ban("req.http.host == rstat.net"); return(synth(200, "Cache cleared")); } + + if (!req.http.X-Forwarded-Proto) { + if(std.port(server.ip) == 443 || std.port(server.ip) == 8443) { + set req.http.X-Forwarded-Proto = "https"; + } else { + set req.http.X-Forwarded-Proto = "https"; + } + } # Cache static files - if (req.url ~ "\.(css|js|avif|webp|png|jpe?g|gif|ico|svg|woff2?|eot|ttf|otf|json|csv|pdf|mp4|webm|ogg|mp3|wav|flac)$") { + if (req.url ~ "^[^?]*\.(7z|avi|bmp|bz2|css|csv|doc|docx|eot|flac|flv|gif|gz|ico|jpeg|jpg|js|less|mka|mkv|mov|mp3|mp4|mpeg|mpg|odt|ogg|ogm|opus|otf|pdf|png|ppt|pptx|rar|rtf|svg|svgz|swf|tar|tbz|tgz|ttf|txt|txz|wav|webm|webp|woff|woff2|xls|xlsx|xml|xz|zip)(\?.*)?$") { unset req.http.Cookie; return(hash); } @@ -38,6 +49,10 @@ sub vcl_recv { return(hash); } +sub vcl_hash { + hash_data(req.http.X-Forwarded-Proto); +} + sub vcl_backend_response { # Cache static files and other content in Varnish for 1 year set beresp.ttl = 1m;