Blockieren des Zugriffs aus einem bestimmten Land: Unterschied zwischen den Versionen

 
(9 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 1: Zeile 1:
[[category:fertig]]
+
[[category:fertig]][[category:Webhosting]]
  
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 [https://dev.maxmind.com/geoip/legacy/codes '''hier''']), was man sperren möchte, einfügen:
+
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 [https://www.geonames.org/countries/ '''hier''']), was man sperren möchte, einfügen:
  
 
== Mithilfe von mod_maxminddb in der .htaccess: ==
 
== Mithilfe von mod_maxminddb in der .htaccess: ==
  
'''1. Beispiel: China
+
=== Blockieren von IPs eines Landes ===
'''
+
 
 +
'''Grundsätzlich:'''  
 +
 
 
  <IfModule mod_maxminddb.c>
 
  <IfModule mod_maxminddb.c>
MaxMindDBEnable On
+
  MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
+
  MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code
+
  MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(CN) BlockCountry
+
  SetEnvIf MM_COUNTRY_CODE ^(Country_Code) BlockCountry
Deny from env=BlockCountry
+
  Deny from env=BlockCountry
 
  </IfModule>
 
  </IfModule>
  
'''2. Beispiel: Russland & China'''
+
'''Beispiel: Russland & China & Vietnam''':
  
 
  <IfModule mod_maxminddb.c>
 
  <IfModule mod_maxminddb.c>
MaxMindDBEnable On
+
  MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
+
  MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code
+
  MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(RU|CN) BlockCountry
+
  SetEnvIf MM_COUNTRY_CODE ^(RU|CN|VN) BlockCountry
Deny from env=BlockCountry
+
  Deny from env=BlockCountry
 
  </IfModule>
 
  </IfModule>
  
== Mithilfe von mod_geoip in der .htaccess: ==
+
==== Erlauben von IPs eines Landes ====
'''VERALTET: Nur auf älteren Webservern möglich (Apache HTTPD 2.2.x). Wenn Sie überprüfen möchten, welche Webserver-Version bei Ihnen vorhanden ist, schauen Sie im DCP unter Webspace -> Server-Infos.'''
 
  
'''1. Beispiel: China'''  
+
'''Grundsätzlich:'''  
  
  GeoIPEnable On   
+
  <IfModule mod_maxminddb.c>
SetEnvIf GEOIP_COUNTRY_CODE CN DenyCountry
+
  MaxMindDBEnable On
Allow from all
+
   MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
Deny from env=DenyCountry
+
  MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
 +
  SetEnvIf MM_COUNTRY_CODE ^(Country_Code) AllowCountry
 +
  Order Allow,Deny
 +
  Allow from env=AllowCountry
 +
</IfModule>
  
'''2. Beispiel: Russland & China & Südkorea'''
 
  
GeoIPEnable On 
+
'''Beispiel: Deutschland''':
SetEnvIf GEOIP_COUNTRY_CODE CN DenyCountry
 
SetEnvIf GEOIP_COUNTRY_CODE RU DenyCountry
 
SetEnvIf GEOIP_COUNTRY_CODE KR DenyCountry 
 
Allow from all
 
Deny from env=DenyCountry
 
 
 
==== Aktivierung mittels PHP: ====
 
 
 
Hierbei einfach in die php.ini folgendes einfügen:
 
extension=geoip.so
 
  
 +
<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: https://countrycode.org/
+
'''Eine Liste für die verschiedenen Ländercodes (ISO-3166 alpha2): https://www.geonames.org/countries/'''
'''
 

Aktuelle Version vom 19. Dezember 2023, 10:42 Uhr


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:

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
 Deny from env=BlockCountry
</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
 Deny from env=BlockCountry
</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/