os : rocky 8.x
nginx 설치 : yum 최신버전 설치 진행
기본 yum 버전으로 nginx를 설치 진행시 기본적으로 geoip2 모듈을 사용할수 없다
추가로 구성하는 방법을 안내
1. geoip2 설치를 위해서 libmaxminddb를 설치 진행
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@xinet ~]# yum -y install autoconf automake libtool [root@xinet ~]# git clone --recursive https://github.com/maxmind/libmaxminddb [root@xinet ~]# cd libmaxminddb/ [root@xinet libmaxminddb]# ./bootstrap [root@xinet libmaxminddb]# ./configure [root@xinet libmaxminddb]# make [root@xinet libmaxminddb]# make install |
2. 라이브러리 등록
1 2 3 4 5 |
[root@xinet libmaxminddb]# vi /etc/ld.so.conf /usr/local/lib [root@xinet libmaxminddb]# ldconfig |
3. 모듈 다운로드
1 2 3 |
[root@xinet ~]# cd /usr/local/src [root@xinet /usr/local/src]# git clone https://github.com/leev/ngx_http_geoip2_module.git |
4. 현재 설치된 버전의 nginx 파일 다운로드
1 2 3 4 5 6 7 |
### 현재설치된 버전 확인 [root@xinet ~]# nginx -v nginx version: nginx/1.27.0 ### 다운로드 [root@xinet ~]# wget https://nginx.org/download/nginx-1.27.0.tar.gz |
5. 다운로드된 파일 압축 해제 후 모듈 설치
1 2 3 4 5 6 7 8 9 |
[root@xinet ~]# wget https://nginx.org/download/nginx-1.27.0.tar.gz [root@xinet ~]# tar xvfz nginx-1.27.0.tar.gz [root@xinet ~]# cd nginx-1.27.0/ [root@xinet nginx-1.27.0]# ./configure --with-compat --add-dynamic-module=/usr/local/src/ngx_http_geoip2_module [root@xinet nginx-1.27.0]# make modules |
6. 모듈 확인 및 복사
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@xinet nginx-1.27.0]# ls -l objs/ 합계 232 -rw-r--r-- 1 root root 41784 6월 4 18:30 Makefile drwxr-xr-x 3 root root 4096 6월 4 18:30 addon -rw-r--r-- 1 root root 20362 6월 4 18:30 autoconf.err -rw-r--r-- 1 root root 7935 6월 4 18:30 ngx_auto_config.h -rw-r--r-- 1 root root 657 6월 4 18:30 ngx_auto_headers.h -rwxr-xr-x 1 root root 99840 6월 4 18:30 ngx_http_geoip2_module.so -rw-r--r-- 1 root root 282 6월 4 18:30 ngx_http_geoip2_module_modules.c -rw-r--r-- 1 root root 33672 6월 4 18:30 ngx_http_geoip2_module_modules.o -rw-r--r-- 1 root root 5856 6월 4 18:30 ngx_modules.c drwxr-xr-x 9 root root 4096 6월 4 18:30 src [root@xinet nginx-1.27.0]# cp -a objs/ngx_http_geoip2_module.so /etc/nginx/modules/ |
7. nginx 에 모듈 등록 후 geoip2 설정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
[root@xinet ~]# vi /etc/nginx/nginx.conf user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; load_module /etc/nginx/modules/ngx_http_geoip2_module.so; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; index index.html index.htm index.php; ###GEOIP geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_country_code source=$remote_addr country iso_code; $geoip2_country_name source=$remote_addr country names en; } ###GEOIP2 CITY geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb { auto_reload 5m; $geoip2_city_name source=$remote_addr city names en; } ### log format log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" $geoip2_country_code $geoip2_city_name $ssl_protocol'; access_log /var/log/nginx/access.log main; ### version hide server_tokens off; ### header hide # hide_server_tokens on; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } |
위 설정값중 mmdb 파일은
https://xinet.kr/?p=2736 해당 페이지 내용 확인 (
geoipupdate 4.1.5 install ( GeoLite2-ASN.mmdb GeoLite2-City.mmdb GeoLite2-Country.mmdb)
8. 검수 확인
1 2 3 |
[root@xinet ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful |
9.이상 없으면 재시작
1 |
[root@xinet ~]# systemctl restart nginx |
10. 로그 확인
1 2 3 4 5 6 |
58.75.69.82 - - [13/Jun/2024:11:25:46 +0900] "GET /wp-content/themes/Blog_Shop/openSrc/lightbox/img/prev.png HTTP/3.0" 200 1360 "https://xinet.kr/wp-content/themes/Blog_Shop/openSrc/lightbox/css/lightbox.css?ver=5.0.4" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-" KR Gangnam-gu TLSv1.3 58.75.69.82 - - [13/Jun/2024:11:25:46 +0900] "GET /wp-content/themes/Blog_Shop/openSrc/lightbox/img/next.png HTTP/3.0" 200 1350 "https://xinet.kr/wp-content/themes/Blog_Shop/openSrc/lightbox/css/lightbox.css?ver=5.0.4" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-" KR Gangnam-gu TLSv1.3 58.75.69.82 - - [13/Jun/2024:11:25:46 +0900] "GET /wp-content/themes/Blog_Shop/openSrc/lightbox/img/loading.gif HTTP/3.0" 200 8476 "https://xinet.kr/wp-content/themes/Blog_Shop/openSrc/lightbox/css/lightbox.css?ver=5.0.4" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-" KR Gangnam-gu TLSv1.3 58.75.69.82 - - [13/Jun/2024:11:25:46 +0900] "GET /wp-content/themes/Blog_Shop/openSrc/lightbox/img/close.png HTTP/3.0" 200 280 "https://xinet.kr/wp-content/themes/Blog_Shop/openSrc/lightbox/css/lightbox.css?ver=5.0.4" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-" KR Gangnam-gu TLSv1.3 58.75.69.82 - - [13/Jun/2024:11:25:46 +0900] "GET /wp-content/themes/Blog_Shop/webfont/NanumGothic-Regular.woff2?20991231 HTTP/3.0" 200 696072 "https://xinet.kr/wp-content/themes/Blog_Shop/css/webfont-local.css?ver=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-" KR Gangnam-gu TLSv1.3 58.75.69.82 - - [13/Jun/2024:11:25:46 +0900] "GET /wp-content/themes/Blog_Shop/webfont/NanumGothic-Bold.woff2?20991231 HTTP/3.0" 200 721556 "https://xinet.kr/wp-content/themes/Blog_Shop/css/webfont-local.css?ver=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-" KR Gangnam-gu TLSv1.3 |