Länder via mod_geoip sperren

Über das Modul mod_geoip des Apache kann der Zugriff anhand der Geo-Location der IPs gesteuert werden.

Hinweis: Eine gegensätzliche Regelung (z.B. in einer vom Hersteller gelieferten .htaccess) kann die Regeln unwirksam machen.

Länderspezifisches

Blacklisting am Beispiel von China und Japan sperren:

<IfModule mod_geoip.c>
GeoIPEnable On
SetEnvIf GEOIP_COUNTRY_CODE JP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
    <RequireAll>
        Require all granted
        Require not env BlockCountry
    </RequireAll>
</IfModule>

Whitelisting am Beispiel von nur Deutschland und US erlauben:

<IfModule mod_geoip.c>
GeoIPEnable On
SetEnvIf GEOIP_COUNTRY_CODE DE AllowCountry
# allow US for GoogleBot, Paypal etc. 
SetEnvIf GEOIP_COUNTRY_CODE US AllowCountry
        Require env AllowCountry
</IfModule>

In den oben genannten Beispiel kann der Code-Block um beliebig viele SetEnvIf-Zeilen erweitert und der Block / Allow-Radius erweitert werden.
Die Länder müssen immer mit zweistelligem ISO Code angegeben werden. Eine Liste der Ländercodes im ISO-Format ist hier zu finden: https://de.wikipedia.org/wiki/ISO-3166-1-Kodierliste

Kontinentspezifisches

Über mod_geoip können auch die Zugriffe durch ganze Kontinente gesteuert werden.

Blacklisting am Beispiel von Asien sperren:

<IfModule mod_geoip.c>
GeoIPEnable On
SetEnvIf GEOIP_CONTINENT_CODE AS BlockContinent
    <RequireAll>
        Require all granted
        Require not env BlockContinent
    </RequireAll>
</IfModule>

Whitelisting am Beispiel von nur Europa und US erlauben:

<IfModule mod_geoip.c>
GeoIPEnable On
SetEnvIf GEOIP_CONTINENT_CODE EU AllowContinent
SetEnvIf GEOIP_COUNTRY_CODE US AllowCountry
Require env AllowCountry
Require env AllowContinent
</IfModule>

Die Möglichen Kürzel sind hier folgende:

AF – Africa
AN – Antarctica
AS – Asia
EU – Europe
NA – North America
OC – Oceania
SA – South America

Aktualisiert am 1. Oktober 2020

War dieser Artikel hilfreich?

Ähnliche Artikel