HTTPヘッダに特定の値をつけたので、それを Apache のログファイルに出力したい。
でも事情があって httpd.conf は手を入れられない...
そんなときは conf.d 以下に独自のファイルをつくります。
※RedHat系OSでのディレクトリにあわせて記載しているので、適宜読み替えてください。
- /etc/httpd/conf.d/hoge.conf を以下のように作成
<VirtualHost *:80>
CustomLog logs/access_log hoge
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Original-Header}i\"" hoge
</VirtualHost>
- 設定したら、構文エラーがないかチェックしてリスタート
/etc/init.d/httpd configtest
#=> Syntax OK
/etc/init.d/httpd restart
- /var/log/httpd/access_log を確認
xxx.xxx.xxx.xxx - - [22/May/2014:12:00:00 +0900] "GET /index.html HTTP/1.1" 200 3000 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36" "(Original-Headerの中身)"