커피닉스, 시스템 엔지니어의 쉼터
  nginx, apache에서 POST 로그 남기기 작성일 : 2014/02/03 18:00
 
  • 글쓴이 : 좋은진호 ( http://coffeenix.net/ )
  • 조회수 : 17248
     
    제  목 : nginx, apache에서 POST 로그 남기기
    작성자 : 좋은진호(truefeel, http://coffeenix.net/ )
    작성일 : 2014.1.28(화)

    1. nginx 설정

    log_format 설정에 $request_body 변수를 추가해주면 된다.

    1) http {} 내에

     
        log_format  post_log '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                           '"$http_user_agent" $request_time "$request_body"';
     


    2) location {} 내에

     
    # POST log
    if ( $request_method = "POST" ) {
       access_log  /LOG/httpd-post.log    post_log;
       access_log  /LOG/httpd-access.log  main;
    }
     


    access_log를 2개 지정한 것은 POST의 요청에 대해 2개 로그파일에 각각 남기기 위해서다. 1) httpd-access.log파일에는 POST요청을 했다는 기본 로그를, 2) httpd-post.log에는 POST 기본 사항 + POST data 로그도 함께 남긴다.

    [ 로그 예 ]
     
    192.168.123.111 - - [28/Jan/2014:16:10:33 +0900] "POST /board/check.html HTTP/1.1" 200 1025 "http://...생략.../board/check.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" 0.001 "mode=editaction&docs=work&viewflg=html&contents=aaaaaaaaaaa"
     



    2. 아파치(apache) dumpio 모듈

     
    DumpIOInput On
    DumpIOLogLevel debug
    LogLevel debug
     


    http://coffeenix.net/bbs/viewtopic.php?p=5824 (2009년)에도 썼지만 단점이 많아 이 모듈은 추천하지 않는다.

    - 로그는 error log 파일에 남게되며
    - 로그가 너무 많이 남아서 실용성이 없다. (정말 너무 많다.)
    - 그리고, 어떤 IP를 남기지 않으므로 어디서 요청이 들어온 것인지 알 수 없다.
    - POST만을 위한 모듈이 아니므로, GET 요청의 경우도 Request 값이 상세하게 로그로 남는다.


    3. 아파치 dumpost 모듈

    POST 데이터를 로그로 남기는 mod_dumpost 모듈( https://github.com/danghvu/mod_dumpost )을 설치한다.

     
    DumpPostHeaderAdd Content-Type
    DumpPostLogFile /LOG/httpd-post.log
     


    - DumpPostHeaderAdd : 로그에 추가로 남길 헤더를 지정한다. 여러 헤더를 지정할 경우 'Referer Host Cookie Content-Type' 처럼 공백으로 구분하면 된다. 그러나 Content-Type 외에는 지정하지 않는게 좋다. 다른 헤더명까지 지정할 경우 그 헤더가 GET요청에도 포함되어 있다면 GET요청도 로그에 남기 때문이다.
    - DumpPostLogFile   : 로그파일명을 지정한다. 지정하지 않으면 error log에 남긴다. 단, error log에 남을 때는 LogLevel이 Info 이상어야 한다.

    [ 로그 예 ]
     
    [Tue Jan 28 17:36:19 2014] 192.168.123.111 "POST /board/check.html HTTP/1.1" application/x-www-form-urlencoded mode=editaction&docs=work&viewflg=html&contents=aaaaaaaaaaaaa
     



    커피닉스, 시스템 엔지니어의 쉼터 / URL : http://coffeenix.net/board_view.php?bd_code=1745