기존에 geoip 사용을 하였는데 이제 더이상 사용하지 않으며 geoip 대신 속도가 좀더 빠른 maxminddb를 사용하는 방법이다
1. 설치
|
1 |
[root@totalmonitoring ~]# dnf install libmaxminddb mod_maxminddb -y |
2. 해당 경로에 다운로드 없으면 폴더 생성 / 최신 파일 다운로드
|
1 2 3 4 |
[root@totalmonitoring ~]# cd /usr/share/GeoIP/ [root@totalmonitoring ~]# rm -f *.mmdb [root@totalmonitoring ~]# wget xinet.kr/data/geoip/GeoLite2-City.mmdb [root@totalmonitoring ~]# wget xinet.kr/data/geoip/GeoLite2-Country.mmdb |
3. apache 환경설정에 추가
|
1 2 3 4 5 6 7 8 |
root@totalmonitoring conf.d]# vi /etc/httpd/conf.d/maxminddb.conf <IfModule mod_maxminddb.c> MaxMindDBEnable On MaxMindDBFile COUNTRY_DB /usr/share/GeoIP/GeoLite2-Country.mmdb MaxMindDBFile CITY_DB /usr/share/GeoIP/GeoLite2-City.mmdb MaxMindDBEnv GEOIP_COUNTRY_CODE COUNTRY_DB/country/iso_code </IfModule> |
4. 국가코드 로그에 설정
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@totalmonitoring ~]# vi /etc/httpd/conf/httpd.conf <IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i %{GEOIP_COUNTRY_CODE}e" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O %{GEOIP_COUNTRY_CODE}e" combinedio </IfModule> #CustomLog "logs/access_log" common CustomLog "logs/access_log" combined </IfModule> |
5. 캐나다 및 중국 차단시 전역 설정시
|
1 2 3 4 5 6 7 8 9 10 |
[root@totalmonitoring ~]# vi /etc/httpd/conf/httpd.conf <Location /> <RequireAll> Require all granted Require expr %{ENV:GEOIP_COUNTRY_CODE} != 'CN' Require expr %{ENV:GEOIP_COUNTRY_CODE} != 'CA' </RequireAll> </Location> |
6. 반대로 한국만 허용하고 나머지 국가 모두 차단시
|
1 2 3 4 5 6 7 8 9 |
[root@totalmonitoring ~]# vi /etc/httpd/conf/httpd.conf <Location /> <RequireAll> Require all granted Require expr "%{ENV:GEOIP_COUNTRY_CODE} == 'KR'" </RequireAll> </Location> |