Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@marcofbb
Created April 3, 2020 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcofbb/c8262f410d02a38eea71bfaa58a78ce3 to your computer and use it in GitHub Desktop.
Save marcofbb/c8262f410d02a38eea71bfaa58a78ce3 to your computer and use it in GitHub Desktop.
Varnish cache different for each country with Cloudflare header
## ## Not complete default.vcl code
sub vcl_recv {
set req.http.IPCountry = "no-specified";
# usage ISO 3166-1 alpha-2 ( https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 )
## If I want to group BR and US in same group cache
if (req.http.CF-IPCountry == "BR" || req.http.CF-IPCountry == "US") {
set req.http.IPCountry = "group-br-and-us";
} else {
set req.http.IPCountry = req.http.CF-IPCountry;
}
}
sub vcl_hash {
hash_data(req.url);
if (req.http.IPCountry) {
hash_data(req.http.IPCountry);
}
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (lookup);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment