Nginx logformat json 구조로 남기기
IT/Server
2023. 2. 3. 10:39
728x90
nginx 로그를 카프카로 전송에 용이하게 로그를 json 구조로 남길 필요가 있었다.
json 구조로 남기는 부분을 기록한다.
nginx에서 지원하는 변수 리스트
http://nginx.org/en/docs/varindex.html
nginx 로그 sample
http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
실제 작업시 nginx 설정
http {
log_format json_format escape=json '{"proxy_add_x_forwarded_for":"$proxy_add_x_forwarded_for",'
'"remote_user_ip":"$remote_user",'
'"time_local":"[$time_local]",'
'"request":"$request",'
'"status":"$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"request_time":"$request_time",'
'"upstream_response_time":"$upstream_response_time",'
'"userid":"$cookie__userId",'
'"request_body":"$request_body"}';
}
format을 지정한다.
access_log /var/log/nginx/admin-nata-access.log json_format;
실제 로그가 json구조로 남는것을 확인 할 수 있다.
'IT > Server' 카테고리의 다른 글
라즈베리 파이에서 GUI VNC에서 한글꺠짐현상 변경 (0) | 2023.04.03 |
---|---|
라즈베리 파이 GUI 원격데스크톱 VNC 연결하기 (0) | 2023.04.03 |
오라클 무료 클라우드 서비스 소개 (0) | 2023.02.22 |
[톰켓] tomcat에서의 OutOfMemoryError 발생시 자동 Heap 덤프 생성 방법. (0) | 2017.08.17 |
[톰켓] JConsole을 통한 원격지 모니터링 환경설정 (0) | 2017.06.08 |