Skip to content

Instantly share code, notes, and snippets.

@thinkingcap
Last active July 20, 2026 05:50
Show Gist options
  • Select an option

  • Save thinkingcap/fccee513a49fbebd907a94a87423a23d to your computer and use it in GitHub Desktop.

Select an option

Save thinkingcap/fccee513a49fbebd907a94a87423a23d to your computer and use it in GitHub Desktop.
/etc/nginx/main-extra.conf
# Geo location setup
geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb {
auto_reload 60m;
$geoip2_continent_code default=XX source=$remote_addr continent code;
$geoip2_country_code default=XX source=$remote_addr country iso_code;
}
map $geoip2_country_code $allowed_country {
default 0;
XX 0; # explicit: unknown IPs are not allowed
AU 1;
CA 1;
GB 1;
NZ 1;
US 1;
SG 1;
# Add other country codes as needed
}
map $geoip2_continent_code $blocked_continent {
default 0;
XX 0; # explicit treatment of unknown continent
AF 1;
AN 1;
SA 1;
EU 1;
AS 1;
# Add other countinent codes as needed OC, NA
}
#location ~* ^/(shop|cart|checkout|product)
location ~* ^/(shop|product-category|product-tag) {
if ($allowed_country = 0) {
return 444;
}
try_files $uri $uri/ /index.php?$args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment