intra-mart WebPlatform の access.log に X-Forwarded-For を出力する方法。

この CookBook では、intra-mart WebPlatform の access.log に X-Forwarded-For を出力する方法について紹介しています。
フロントに Web サーバや LB が建っている場合、javax.servlet.ServletRequest#getRemoteAddr() がクライアントのIPアドレスを返却しない場合があります。(mod_rewrite(Apache) や ARR(IIS) を利用している場合)
この場合、X-Forwarded-For や、X-Real-IP などのヘッダーを用いて、接続元の情報を受け渡すことがあります。
このような場合でも、以下のような設定を追加することにより、特定のヘッダーを access.log に出力することができます。

/usr/local/imart/conf/http.xml
      <access-log path="log/http/access.log"

            format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" %{X-Forwarded-For}i'
            rollover-period="1W"/>

上記の例では、%{X-Forwarded-For}i を埋め込むことで、X-Forwarded-For ヘッダーの値を access.log に出力しています。
このように、http.xml を編集することで、access.log に接続元の情報を出力することができます。
是非ご活用ください。