This site is now 100% read-only, and retired.

XML logo

Virtual hostname in Apache wildcard-host logs
Posted by lee on Thu 23 Feb 2006 at 11:27
Tags:

One of the apache websites I'm configuring has many different ServerAlias directives, some of which contain wildcard domain components. I need to be able to split the logs up, and produce statistics per host. However, many files are shared amongst different hosts, so I can't use the file path to differenciate them. Referals are not reliable enough.

Looking at the Apache2 documentation for mod_log_config gives an example that uses "%v" in a LogFormat directive to store the virtual host in the log. However, this is the "ServerName" and not necessarily the host it was called as - what I'm actually looking for is the Hostname requested by the client.

Handily, this can be obtained using "%{Host}i", thus my log format can be specified as follows:

LogFormat "%{Host}i %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
CustomLog /var/log/apache-vhost/images.example.com/access_log vhost_combined

I now have the option of splitting the logs using a simple script, or configuring a stats analyzer to only check for the hosts I need stats for. The following awstats config should do the trick:

LogFormat="%virtualname %host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot" 
SiteDomain="foobar6.example.com"