vcl 4.1; # ============================================================================= # varnish.vcl — Stack hitch + varnish # Varnish reçoit le trafic de hitch avec le PROXY protocol header. # accept_from est limité à 127.0.0.1 (hitch tourne en local). # ============================================================================= # Activation du PROXY protocol : Varnish récupère la vraie IP client depuis # le header PROXY envoyé par hitch. # (configuré via -a "...PROXY" dans la ligne de commande varnishd) backend default { .host = "127.0.0.1"; .port = "8080"; .probe = { .url = "/health"; .interval = 5s; .timeout = 2s; .window = 3; .threshold = 2; } } sub vcl_recv { # Normalisation URL if (req.url ~ "//") { set req.url = regsuball(req.url, "//+", "/"); } # Ne pas cacher les mutations if (req.method != "GET" && req.method != "HEAD") { return (pass); } return (hash); } sub vcl_backend_response { set beresp.ttl = 5s; set beresp.grace = 10s; } sub vcl_deliver { # En-têtes de debug pour les tests if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } # Indique que Varnish a traité la requête (vérifiable dans les tests) set resp.http.Via = "1.1 varnish (Varnish/hitch-varnish-test)"; # Expose l'IP client vue par Varnish (après PROXY protocol de hitch) set resp.http.X-Client-IP = client.ip; return (deliver); }