From e8730fd0898a4ee82e1664cb8e58a1a60d8d2c76 Mon Sep 17 00:00:00 2001 From: happybell80 Date: Wed, 22 Oct 2025 22:35:44 +0900 Subject: [PATCH] troubleshooting: 51123 nginx real_ip + JSON access logs; fluent-bit/data-prepper pipeline validation and results --- ...1022_nginx_real_ip_and_logging_pipeline.md | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 troubleshooting/251022_nginx_real_ip_and_logging_pipeline.md diff --git a/troubleshooting/251022_nginx_real_ip_and_logging_pipeline.md b/troubleshooting/251022_nginx_real_ip_and_logging_pipeline.md new file mode 100644 index 0000000..48851b2 --- /dev/null +++ b/troubleshooting/251022_nginx_real_ip_and_logging_pipeline.md @@ -0,0 +1,56 @@ +# 251022 Nginx real_ip 적용 및 JSON 로그 파이프라인 정비 + +- 작성자: admin +- 서버: 51123 +- 관련 저장소: `nginx-infra`, `fluent-bit` +- 변경 일시: 251022 + +## 배경 / 증상 +- 프록시 뒤 실제 IP 미반영 → 모든 요청 IP가 127.0.0.1로 집계되어 IP·지역·차단/레이트리밋 분석 왜곡 발생. +- Nginx 로그 포맷·수집 경로 불일치 → combined 파일 로그(또는 stdout 미사용)로 기록하여 Fluent Bit → Data Prepper 파싱 실패/누락/중복 발생, OpenSearch 분석 품질 저하. + +## 원인 확인 +- real_ip 계열 지시어 미구성: `nginx-infra/nginx.conf` 기본 `access.log`만 정의, `set_real_ip_from/real_ip_header/real_ip_recursive` 없음. +- Fluent Bit는 `/var/log/nginx/access.log`(정규식 파서) 수집 구성으로 JSON 표준 로그 아님: `fluent-bit/fluent-bit.conf` 21행, 38행. + +## 조치 내역 +1) Nginx real_ip 및 JSON 로그 포맷 추가 +- 파일: `nginx-infra/nginx.conf` + - 신뢰 프록시 대역 및 헤더 설정 추가: + - `set_real_ip_from 127.0.0.1;` + - `set_real_ip_from 10.0.0.0/8;` + - `set_real_ip_from 172.16.0.0/12;` + - `set_real_ip_from 192.168.0.0/16;` + - `real_ip_header X-Forwarded-For;` + - `real_ip_recursive on;` + - JSON 로그 포맷 정의 및 파일 출력 전환: + - `log_format robeing_json ...` (time_iso8601, remote_addr, method, uri, status, request_time, upstream_status/response_time, request_id, x_request_id, user_uuid 포함) + - `access_log /var/log/nginx/access.json robeing_json;` + +2) Fluent Bit 수집 경로/파서 정합화 +- 파일: `fluent-bit/fluent-bit.conf` + - Nginx 입력 경로를 `/var/log/nginx/access.json`으로 변경 + - 파서를 `nginx_json`으로 지정 +- 파일: `fluent-bit/parsers.conf` + - `nginx_json` 파서 추가 (Format: json, Time_Key: time) + +3) 커밋/배포 +- `nginx-infra`: main 푸시 (real_ip + JSON access 로그) +- `fluent-bit`: main 푸시 (access.json tail + json 파서) + +## 검증 결과 (51123) +- Containers: fluent-bit running(restarts=0), data-prepper running(restarts=0) +- Nginx: systemd active(running), 80/443 수신; HTTP/HTTPS probe 200 OK +- Data Prepper: health {"healthy": true} +- OpenSearch: 인덱스 `dataprepper-static` 존재(≈5.86M docs), 최근 fluent-bit 에러 없음 + +## 효과 (요약 3줄) +- 실제 IP 반영으로 127.0.0.1 집계 왜곡 해소 → 차단/레이트리밋·지역 분석 정확도 상승 +- JSON 표준 로그와 일관된 수집 경로로 OpenSearch 안정 적재 → 파싱 오류·누락/중복 감소, 대시보드/알림 활용 가능 +- request_id/user_uuid·upstream_* 포함으로 엔드투엔드 추적 가능 → SPA fallback(404→200) 은폐/지연 원인 상관분석 가능 + +## 후속 작업 +- nginx-infra 배포 파이프라인으로 서버(51123) 적용/유지: `nginx -t` → reload +- 대시보드/알람에 `remote_addr`, `request_id`, `upstream_*` 지표 추가 +- 필요 시 신뢰 프록시 대역 확장(외부 L4/프록시 추가 시) +