varnish cache config 1
by trisna dev
JavaScript
vcl 4.0;
# Backend definitions
backend emodal {
.host = "127.0.0.1";
.port = "8080"; # Ganti dengan port yang sesuai
}
backend frestive {
.host = "127.0.0.1";
.port = "8081"; # Ganti dengan port yang sesuai
}
backend lmu {
.host = "127.0.0.1";
.port = "8082"; # Ganti dengan port yang sesuai
}
# Subroutine to determine the backend based on the URL
sub vcl_recv {
if (req.url ~ "^/emodal") {
set req.backend_hint = emodal;
} elseif (req.url ~ "^/frestive") {
set req.backend_hint = frestive;
} elseif (req.url ~ "^/lmu") {
set req.backend_hint = lmu;
} else {
return (synth(404, "Not Found"));
}
# Cache control for emodal
if (req.url ~ "^/emodal/keterangan") {
# Cache page "keterangan" for 1 day
set req.http.Cache-Control = "public, max-age=86400";
} else {
# Do not cache other pages for emodal
return (pass);
}
# Cache control for frestive
if (req.url ~ "^/frestive") {
# Cache all pages for frestive
set req.http.Cache-Control = "public, max-age=86400";
}
# Do not cache lmu at all
if (req.url ~ "^/lmu") {
return (pass);
}
# Remove cookies for static resources to improve caching
if (req.url ~ "\.(css|js|jpg|jpeg|png|gif|ico|woff|woff2|ttf|svg)$") {
unset req.http.Cookie;
}
# Normalize the header, remove the port (in case you're testing this on various ports)
set req.http.Host = regsub(req.http.Host, ":[0-9]+", "");
}
# Subroutine to handle the cache hit
sub vcl_hit {
if (obj.ttl >= 0s) {
return (deliver);
}
return (fetch);
}
# Subroutine to handle the cache miss
sub vcl_miss {
return (fetch);
}
# Subroutine to handle the backend response
sub vcl_backend_response {
# Set cache TTL for emodal's "keterangan" page
if (bereq.url ~ "^/emodal/keterangan") {
set beresp.ttl = 1d;
}
# Set cache TTL for frestive
if...