기술문서 GeoIP 를 이용한 Apache 설정 - 국가별 접속 차단
2018.06.13 03:01
GeoIP 란 MaxMind 에서 제공하는 국가별로 IP를 확인할 수 있는 오픈소스 라이브러리로 이를 이용하여 서버에 접근 하는 아이피를 국가별로 관리할 수 있습니다.
1. Apache에 GeoIP 모듈 설치하기
1-1. GeoIP C API 설치하기
# cd /usr/local/src
# wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz
# tar zxvf GeoIP-1.4.8.tar.gz
# cd GeoIP-1.4.8
#./configure --prefix=/usr/local/GeoIP
# make && make install
- GeoIP의 ip목록을 최신정보로 갱신하기 위하여 GeoIP.dat 을 다운받아 설치된 위치에 복사
: 국가 정보 다운로드
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
: 도시 정보 다운로드
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
# gzip -d GeoIP.dat.gz
# gzip -d GeoLiteCity.dat.gz
- 해제된 파일을 GeoIP가 설치된 위치에 덮어쓰기
#cp -a GeoIP.dat /usr/local/GeoIP/share/GeoIP/
#cp -a GeoLiteCity.dat /usr/local/GeoIP/share/GeoIP/
1-2. GeoIP 모듈을 아파치에 설치하기
-mod_geoip 다운
아파치 2.x 용
https://github.com/maxmind/geoip-api-mod_geoip2/archive/1.2.10.tar.gz
wget https://github.com/maxmind/geoip-api-mod_geoip2/archive/1.2.10.tar.gz
# tar zxvf 1.2.10.tar.gz
-> 해제된 위치로 이동 후 c 파일을 apxs 를 이용하여 설치
# cd geoip-api-mod_geoip2-1.2.10
# [아파치 apxs경로] -i -a -L [geoip 설치 디렉토리의 lib 경로] -I [geoip 설치 디렉토리의 include 경로] -l GeoIP -c [mod_geoip.c 경로]
----> 옵션 대소문자 주의 -l GeoIP = 소문자 엘로 시작
# /usr/bin/apxs -i -a -L /usr/local/GeoIP/lib -I /usr/local/GeoIP/include -l GeoIP -c /usr/local/src/geoip-api-mod_geoip2-1.2.10/mod_geoip.c
# ls -al /usr/lib/apache2/modules/mod_geoip.so
# cat /etc/apache2/mods-enabled/mod_geoip.load
- phpinfo 페이지의 Apache Environment 정보에 GEOIP_CONTINENT_CODE, GEOIP_COUNTRY_CODE, GEOIP_COUNTRY_NAME 항목 확인
# vi /etc/apache2/mods-enabled/mod_geoip.conf
특정 국가의 접근 차단
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/local/GeoIP/share/GeoIP/GeoIP.dat
<Location /home>
SetEnvIf GEOIP_COUNTRY_CODE CN go_out
SetEnvIf GEOIP_COUNTRY_CODE RU go_out
SetEnvIf GEOIP_COUNTRY_CODE TH go_out
<Limit GET POST>
Order allow,deny
Allow from all
Deny from env=go_out
</Limit>
</Location>
</IfModule>
특정 국가에만 접근 허용
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/local/GeoIP/share/GeoIP/GeoIP.dat
<Location /home>
SetEnvIf GEOIP_COUNTRY_CODE KR go_in
<Limit GET POST>
Order Deny,Allow
Deny from all
Allow from env=go_in
</Limit>
</Location>
</IfModule>
[cloudflare 적용시]
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/local/GeoIP/share/GeoIP/GeoIP.dat
</IfModule>
<Directory /home/>
SetEnvIf GEOIP_COUNTRY_CODE KR AllowCountry
Allow from env=AllowCountry
allow from 103.21.244.0/22
allow from 103.22.200.0/22
allow from 103.31.4.0/22
allow from 104.16.0.0/12
allow from 108.162.192.0/18
allow from 131.0.72.0/22
allow from 141.101.64.0/18
allow from 162.158.0.0/15
allow from 172.64.0.0/13
allow from 173.245.48.0/20
allow from 188.114.96.0/20
allow from 190.93.240.0/20
allow from 197.234.240.0/22
allow from 198.41.128.0/17
allow from 199.27.128.0/21
Deny from all
</Directory>
[참고]
Cannot load mod_geoip.so into server: libGeoIP.so.1: cannot open shared object file: No such file or directory
에러 발생시
/etc/ld.so.conf 파일에
/usr/local/GeoIP/lib 라인 추가 후
ldconfig 실행 적용
댓글 0
번호 | 제목 | 날짜 | 조회 수 |
---|---|---|---|
64 | tibero 7 install for linux | 2023.11.06 | 20 |
63 | Red Hat Enterprise Linux Certification Matrix for Dell PowerEdge Servers | 2023.11.02 | 14 |
62 | Tibero test sql문, SCHEMA_OBJECT_SAMPLE | 2023.10.25 | 9 |
61 | Tibero 관리 3 | 2023.10.25 | 13 |
60 | Tibero 관리 2 | 2023.10.25 | 23 |
59 | Tibero 접속 및 관리 | 2023.10.25 | 49 |
58 | weblogic wlst 기반 암호화파일 복호화 (AES) | 2021.04.06 | 111 |
57 | weblogic admin 패스워드 변경 방법 | 2021.04.06 | 59 |
56 | wmic useraccount list brief | 2021.04.01 | 28 |
55 | OSI (Open System Interconnection) 모델의 7개 계층구조 | 2019.09.10 | 274 |
54 | TCP/IP Tuning parameter | 2019.03.15 | 2874 |
53 | [python] MySQL 사용법 예제 | 2018.10.24 | 523 |
» | GeoIP 를 이용한 Apache 설정 - 국가별 접속 차단 | 2018.06.13 | 656 |
51 | OSI 7 Layer | 2017.11.01 | 214 |
50 | TCP 프로토콜 Header 구조 | 2017.11.01 | 1554 |
49 | TCP 상태전이 | 2017.11.01 | 614 |
48 | 전자우편 보안 | 2017.11.01 | 280 |
47 | 부팅(Booting) 과정 | 2017.11.01 | 317 |
46 | 디지털 컨텐츠 보호 | 2017.11.01 | 113 |
45 | 윈도우 보안 | 2017.11.01 | 186 |