Tips記事
» 2000年12月06日 00時00分 UPDATE

ApacheのログにWebブラウザの種別やリンク元情報を記録したい

[木田佳克,ITmedia]

 IEを始めとするWebブラウザは,「Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)」などのユーザーエージェントコードを持ってアクセスしている。また,どこのページから訪れたかという情報も,Webブラウズしている人が無意識のうちに記録することができる。これらは,インターネット上で配布されているアクセス記録を行うCGIでもおなじみだろう。

アクセス元表示の例
画面
Webalizerでの表示例

ユーザーエージェント表示の例
画面
Webalizerでの表示例

 Apacheの標準設定では,これらの情報をログに記録しないようになっている。次のように編集をすると記録するように変更が可能だ。

# vi /etc/httpd/conf/httpd.conf

〜中略〜
# The location and format of the access logfile (Common Logfile Format).
#CustomLog /var/log/httpd/access_log common

# If you would like to have agent and referer logfiles, uncomment the
CustomLog /var/log/httpd/referer_log referer
CustomLog /var/log/httpd/agent_log agent

# If you prefer a single logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
CustomLog /var/log/httpd/access_log combined
〜中略〜

 編集後には,httpdの再起動を忘れずに行おう。

# /etc/rc.d/init.d/httpd restart

Copyright © ITmedia, Inc. All Rights Reserved.

注目のテーマ