o/s : rocky linux 8.8
[root@han ~]# httpd -V
Server version: Apache/2.4.37 (rocky)
Server built: Sep 22 2023 23:22:00
1. 먼저 GeoIP yum 으로 설치
1 |
[root@ ]# yum -y install GeoIP.x86_64 GeoIP-GeoLite-data GeoIP-devel |
2. mod_geoip download and install
1 2 3 4 5 6 7 8 |
[root@ ~]# wget https://pkgs.dyn.su/el8/modular/x86_64/httpd/mod_geoip-0:1.2.10-11.el8.x86_64.rpm [root@ ~]# rpm -Uvh mod_geoip-0\:1.2.10-11.el8.x86_64.rpm 경고: mod_geoip-0:1.2.10-11.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 2dcd03a2: NOKEY Verifying... ################################# [100%] 준비 중... ################################# [100%] Updating / installing... 1:mod_geoip-1.2.10-11.el8 ################################# [100%] |
만약 위 링크에서 다운로드가 되지 않는다면 아래 주소에서 다운로드
https://xinet.kr/data/geoip/mod_geoip-0:1.2.10-11.el8.x86_64.rpm
3. 설치가 다 되었다면 확인
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@ ~]# cat /etc/httpd/conf.d/geoip.conf <IfModule mod_geoip.c> GeoIPEnable On GeoIPDBFile /usr/share/GeoIP/GeoIP.dat </IfModule> [root@han ~]# ll /etc/httpd/conf.modules.d/10-geoip.conf -rw-r--r-- 1 root root 45 1월 30 2020 /etc/httpd/conf.modules.d/10-geoip.conf [root@han ~]# cat /etc/httpd/conf.modules.d/10-geoip.conf LoadModule geoip_module modules/mod_geoip.so |
4. 웹로그에 국가코드를 찍힐수 있게 log포맷 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@ ~]# 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. apache 재시작
1 2 3 |
[root@ ~]# httpd -t Syntax OK [root@ ~]# systemctl restart httpd |
6. 로그확인
1 2 3 |
112.x.x200 - - [05/Oct/2023:10:29:25 +0900] "POST /ajax.php HTTP/2.0" 403 199 "https://xinet.kr/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 KR 112.x.x.200 - - [05/Oct/2023:10:30:25 +0900] "POST /ajax.php HTTP/2.0" 403 199 "https://xinet.kr/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 KR 118.x.x.12 - - [05/Oct/2023:10:31:25 +0900] "POST /test.php HTTP/2.0" 403 199 "https://xinet.kr/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 KR |