How to Block Entire Countries from Accessing Your Website

Thaks for your article , very useful to me.

To block various countries, this worked for me:
SecRule GEO:COUNTRY_CODE “@rx ^(UA|ID|YU|LT|EG|RO|BG|TR|RU|PK|MY|CN)$”

To block everything except some countries:
SecRule GEO:COUNTRY_CODE “!@rx ^(US|MX|AR)$”

Using regular expresions let me block various countries or allow acces only to certain countries. This page will be usefull to see a detailed list of operators in modsecurity:
http://nature.berkeley.edu/~casterln/modsecurity/modsecurity2-apache-reference.html#N10883

Hope this help

1 Like