아파치 로그(Apache Log) 관리법

by 조쉬 posted Feb 02, 2017
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

아파치 로그(Apache Log) 관리법
접속자가 많은 사이트에서는 아파치 로그를 관리하는 것도 만만치 않다.
불필요한 정보는 로그에 쌓이지 않도록 처리하는 것이 중요하다.
로그 파일이 크면 클수록 서버에 필요없는 무리를 주므로 날짜별로 분리하여 로그를 남기자.


아파치 환경설정 파일에서 <IfModule log_config_module> 부분을 찾아서 아래와 같이 수정해준다.


<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" 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" combinedio
    </IfModule>

    # 그림 이미지, css, js는 기록하지 않게 처리
    SetEnvIfNoCase Request_URI "\.(jpg|png|gif|css|ico|js|swf)$" notloglist

    #CustomLog "logs/access_log" common
    #CustomLog "logs/access_log" combined
    #CustomLog "|/아파치 설치 경로/bin/rotatelogs /로그를 저장할 경로/파일명 %Y%m%d%H 86400 +540" combined
    # 날짜별로 로그기록 남기기
    CustomLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/access_log_%Y%m%d 86400 +540" combined env=!notloglist  
</IfModule>


※ 86400 + 540 : GMT 기준 + 9시간,  한국시간 0시 기준 파일 분할 목적


/usr/local/apache/conf/extra/httpd-vhosts.conf 파일이 같이 동작되는 경우에는

이곳에 적어준다.

즉, httpd.conf 파일 안에

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

라고 되어 있으면 /usr/local/apache/conf/extra/httpd-vhosts.conf 에 적어준다.

virtualhost 에 적어주는 경우에는 access_log_%Y%m%d 보다는 사이트명을 식별할 수 있는 구분자를 넣어주는게 좋다.