Blockieren des Zugriffs aus einem bestimmten Land


Dieser Artikel befindet sich zur Zeit in Bearbeitung

Falls man gewisse Länder aufgrund von vielen Bot-Aktivitäten sperren möchte, kann man hierbei die Ländererkennung bei apache2 in der .htaccess verwenden. Hierzu braucht man nur ein paar Zeilen mit dem jeweiligen Land (siehe hier), was man sperren möchte, einfügen:

Mithilfe von mod_maxminddb in der .htaccess:

1. Beispiel: China

<IfModule mod_maxminddb.c>
MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(CN) BlockCountry
Deny from env=BlockCountry
</IfModule>

2. Beispiel: Russland & China

<IfModule mod_maxminddb.c>
MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(RU|CN) BlockCountry
Deny from env=BlockCountry
</IfModule>

Mithilfe von mod_geoip in der .htaccess:

1. Beispiel: China

GeoIPEnable On   
SetEnvIf GEOIP_COUNTRY_CODE CN DenyCountry 
Allow from all 
Deny from env=DenyCountry

2. Beispiel: Russland & China

GeoIPEnable On   
SetEnvIf GEOIP_COUNTRY_CODE CN DenyCountry 
SetEnvIf GEOIP_COUNTRY_CODE RU DenyCountry 
SetEnvIf GEOIP_COUNTRY_CODE KR DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE RU DenyCountry  
Allow from all 
Deny from env=DenyCountry

Aktivierung mittels PHP:

Hierbei einfach in die php.ini folgendes einfügen:

extension=geoip.so