It can be done in nginx using geoip2 module.
this block goes to http { part of config, for example
/etc/nginx/conf.d/geoip.conf
geoip2 /usr/share/GeoIP/country_asn.mmdb { # if you have some database update script, you can configure auto reload # auto_reload 1h; $geoip2_asn asn; $geoip2_as_name as_name; $geoip2_continent continent; $geoip2_continent_name continent_name; $geoip2_country country; }
And use it in location
put this in location
if ($geoip2_asn = "AS32934") { return 402; }