1. 개요

아파치 웹 서버의 access log에 JSESSIONID를 남겨보자.

그 전에 기본적인 로그 설정은 다음과 같으며...

LogLevel warn

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    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>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog "logs/access_log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "logs/access_log" combined
</IfModule>

2. 설정

이게 참 쉽지 않습니다.

LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %b %D \"%{JSESSIONID}C\"" common_jsid

원래 위와 같이 설정하고 CustomLog를 common_jsid로 설정하면 Access log에 JSESSIONID가 기록되어야 합는데, 왜인지 안됩니다.

- 127.0.0.1 - - [26/May/2016:09:36:04 +0900] "GET /test.jsp HTTP/1.1" 200 46 5043 "-"
- 127.0.0.1 - - [26/May/2016:09:36:05 +0900] "GET /test.jsp HTTP/1.1" 200 46 6835 "-"
- 127.0.0.1 - - [26/May/2016:09:36:06 +0900] "GET /test.jsp HTTP/1.1" 200 46 7127 "-"

 


3. 재시도

이번에는 test.jsp에 다음 내용을 추가하고,

response.setHeader("JSID", request.getSession().getId());

common_jsid 포맷을 다음과 같이 바꾸고,

LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %b %D \"%{JSESSIONID}C\" \"%{JSID}o\"" common_jsid

다시 시도해 봅니다.

우선 헤더부터 보죠.

Set-Cookie: JSESSIONID=C674DAC26B501B6B0F1B165722168BD5;path=/;HttpOnly
JSID: C674DAC26B501B6B0F1B165722168BD5

이제 Access log를 봅니다.

- 127.0.0.1 - - [26/May/2016:09:46:04 +0900] "GET /test.jsp HTTP/1.1" 200 46 8055 "-" "C674DAC26B501B6B0F1B165722168BD5"

JSID는 가져오고, JSESSIONID는 가져오지 못했습니다.


4. 대안?

아예 Set-Cookie를 찍어볼까요.

LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %b %D \"%{JSESSIONID}C\" \"%{Set-Cookie}o\"" common_jsid

결과는,

- 127.0.0.1 - - [26/May/2016:09:56:57 +0900] "GET /test.jsp HTTP/1.1" 200 46 7949 "-" "JSESSIONID=D9AA85B411506804899A14BC27495B9E;path=/;HttpOnly"
- 127.0.0.1 - - [26/May/2016:09:57:04 +0900] "GET /test.jsp HTTP/1.1" 200 46 4664 "-" "JSESSIONID=ABE8D2711681B33CA6BAFFD765294177;path=/;HttpOnly"
- 127.0.0.1 - - [26/May/2016:09:57:05 +0900] "GET /test.jsp HTTP/1.1" 200 46 6924 "-" "JSESSIONID=51B3DFC24989161201CFB64146CF58FB;path=/;HttpOnly"