LoginSignup
3
3

More than 5 years have passed since last update.

conf.d 以下の設定ファイルでApacheのログフォーマットを制御する

Posted at

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の中身)"
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3