본문으로 건너뛰기
  1. Memo/

Nginx 로그 관련 메모

·
Nginx
작성자
hw5e
page.hw5e.cc
목차

로그를 관리하는 logrotate
#

로그를 얼마나 남길지, 어떻게 파일을 분리할지, 압축할지를 설정 가능한 것 같다.

cat /etc/logrotate.d/nginx
/var/log.hdd/nginx/*.log {
        weekly
        missingok
        rotate 14
        compress
        delaycompress
        notifempty
        create 0640 www-data adm
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi \
        endscript
        postrotate
                invoke-rc.d nginx rotate >/dev/null 2>&1
        endscript
}

로그에 프록시의 x-헤더로 받은 IP로 표시하는 예시
#

서버 앞에 역방향 프록시가 있으면 로그에 프록시 서버의 IP 주소가 찍힌다. 다음 방법으로 프록시의 IP 대신 x헤더로 넘어온 IP 주소를 로그에 적히게 할 수 있다.

log_format combined_realip '$http_x_forwarded_for - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';

access_log /var/log/nginx/access.log combined_realip;
Reply by Email