Blockieren des Zugriffs aus einem bestimmten Land: Unterschied zwischen den Versionen
Rb (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
Rb (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
| Zeile 9: | Zeile 9: | ||
'''Grundsätzlich:''' | '''Grundsätzlich:''' | ||
<IfModule mod_maxminddb.c> | <IfModule mod_maxminddb.c> | ||
MaxMindDBEnable On | MaxMindDBEnable On | ||
MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb | MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb | ||
MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code | MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code | ||
SetEnvIf MM_COUNTRY_CODE ^(Country_Code)$ BlockCountry | SetEnvIf MM_COUNTRY_CODE ^(Country_Code)$ BlockCountry | ||
<RequireAll> | <RequireAll> | ||
Require all granted | Require all granted | ||
Require not env BlockCountry | Require not env BlockCountry | ||
</RequireAll> | </RequireAll> | ||
</IfModule> | </IfModule> | ||
'''Beispiel: Russland & China & Vietnam''': | '''Beispiel: Russland & China & Vietnam''': | ||
<IfModule mod_maxminddb.c> | <IfModule mod_maxminddb.c> | ||
MaxMindDBEnable On | MaxMindDBEnable On | ||
MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb | MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb | ||
MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code | MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code | ||
SetEnvIf MM_COUNTRY_CODE ^(RU|CN|VN)$ BlockCountry | SetEnvIf MM_COUNTRY_CODE ^(RU|CN|VN)$ BlockCountry | ||
<RequireAll> | <RequireAll> | ||
Require all granted | Require all granted | ||
Require not env BlockCountry | Require not env BlockCountry | ||
</RequireAll> | </RequireAll> | ||
</IfModule> | </IfModule> | ||
Aktuelle Version vom 7. April 2026, 16:35 Uhr
Falls man gewisse Länder aufgrund von vielen Bot-Aktivitäten sperren möchte, kann man hierbei die Ländererkennung (MaxMind GeoIP) 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 (Geo IP) in der .htaccess:
Blockieren von IPs eines Landes
Grundsätzlich:
<IfModule mod_maxminddb.c>
MaxMindDBEnable On
MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(Country_Code)$ BlockCountry
<RequireAll>
Require all granted
Require not env BlockCountry
</RequireAll>
</IfModule>
Beispiel: Russland & China & Vietnam:
<IfModule mod_maxminddb.c>
MaxMindDBEnable On
MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(RU|CN|VN)$ BlockCountry
<RequireAll>
Require all granted
Require not env BlockCountry
</RequireAll>
</IfModule>
Erlauben von IPs eines Landes
Grundsätzlich:
<IfModule mod_maxminddb.c> MaxMindDBEnable On MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code SetEnvIf MM_COUNTRY_CODE ^(Country_Code) AllowCountry Order Allow,Deny Allow from env=AllowCountry </IfModule>
Beispiel: Deutschland:
<IfModule mod_maxminddb.c> MaxMindDBEnable On MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code SetEnvIf MM_COUNTRY_CODE ^(DE) AllowCountry Order Allow,Deny Allow from env=AllowCountry </IfModule>
Wichtig: Dadurch werden nur IP-Adressen aus Deutschland erlaubt.
Eine Liste für die verschiedenen Ländercodes (ISO-3166 alpha2): https://www.geonames.org/countries/
