Apache に MaxMind DB モジュールをインストール

以前は「mod_geoip」と呼ばれていたモジュールは「mod_maxminddb」になった。

そこで新しい GeoIP の Apache モジュールである MaxMind DB Apache Module について説明する。

これにより、特定の国からのアクセスを拒否したり、日本だけを許可したり出来る。

※ このモジュールは「Apache に GeoIP をインストール」の置き換えです。

インストール

# dnf install mod_maxminddb

設定

<IfModule mod_maxminddb.c>
    MaxMindDBEnable On

    # GeoLite2 databases (provided by the RPM packages geolite2-country
    # and geolite2-city) are free IP geolocation databases comparable to,
    # but less accurate than, MaxMind's commercial GeoIP2 databases.
    MaxMindDBFile COUNTRY_DB /usr/share/GeoIP/GeoLite2-Country.mmdb
    MaxMindDBFile CITY_DB    /usr/share/GeoIP/GeoLite2-City.mmdb
    MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code

    <Location "/">
        # 特定の国をブロック
        SetEnvIf MM_COUNTRY_CODE ^(RU|DE|CN|HK|KR|KP|NL) BlockCountry
        Order Deny,Allow
        Deny from env=BlockCountry
        Allow from all
    </Location>

    <Directory /var/www/wsgi>
        # 日本だけを許可
        Order Allow,Deny
        SetEnvIf MM_COUNTRY_CODE JP AllowCountry
        Allow from 192.168.0.0/16
        Allow from 127.0.0.0/8
        Allow from googlebot.com
        Allow from google.com
        Allow from env=AllowCountry
        Deny from all
    </Directory>
</IfModule>

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です