Created
April 3, 2020 01:53
-
-
Save marcofbb/c8262f410d02a38eea71bfaa58a78ce3 to your computer and use it in GitHub Desktop.
Varnish cache different for each country with Cloudflare header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ## 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