Apache Reverse Proxy with GeoIP
O Apache pode usar os módulos mod_geoip ou mod_maxminddb para restringir o acesso com base no país de origem da requisição ao serviço.
Abaixo explicamos como implementar esta modalidade de proteção.
a. Instalar Modulo GeoIP Module
- Para instalar o GeoIP executar o comando sudo apt-get install libapache2-mod-geoip geoip-database
- Para instalar o GeoLite2: Você precisa instalar os modulo  mod_maxminddbsudo apt-get install libmaxminddb-dev mmdb-bin
b. Configurar o Apache com GeoIP
Após instalar os módulos GeoIP or GeoLite2, necessário configurar o apache:
- Habilitar os módulos sudo a2enmod geoip
- Configurar o virtual host que está sendo exposto no proxyreverso utilizando como referencia o EXEMPLO abaixo:
<VirtualHost *:80>
    ServerName yourdomain.com
    ProxyPass / http://backend_server/
    ProxyPassReverse / http://backend_server/
    GeoIPEnable On
    GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
    SetEnvIf GEOIP_COUNTRY_CODE BR AllowCountry
    SetEnvIf GEOIP_COUNTRY_CODE IT AllowCountry
    SetEnvIf GEOIP_COUNTRY_CODE AR AllowCountry
    SetEnvIf GEOIP_COUNTRY_CODE MA AllowCountry
    SetEnvIf GEOIP_COUNTRY_CODE MX AllowCountry
    <Location />
        Order deny,allow
        Deny from all
        Allow from env=AllowCountry
    </Location>
</VirtualHost>
- A variavel SetEnvIf GEOIP_COUNTRY_CODEpermite o acesso a partir destes paises.
- As diretivas Order deny,allow e Deny from all bloqueiam todo o acesso, exceto para os países definidos em AllowCountry.
Testado no Ubuntu 20.04.6.
