How to: Apache logging using name-based virtual hosts
I spent a bit of time today getting logging to work correctly on my server. The server is using name-based virtual hosts, so getting logging set up was going to take an extra step. The first thing was to add another LogFormat line in the apache2.conf file which would use the comonvhost option.
LogFormat “%v %h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”" comonvhost
LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”" combined
LogFormat “%h %l %u %t \”%r\” %>s %b” common
LogFormat “%{Referer}i -> %U” referer
LogFormat “%{User-agent}i” agent
Adding this LogFormat line, lets Apache distinguish between the various virtual hosts when logging. To learn more about what the options mean (i.e. %u, etc.) you can look here. Each virtual host was given its own log file, so in the VirtualHost directive, the following line was added using CustomLog:
ServerName www.sematopia.com
DocumentRoot /var/www/sematopia.com
ServerAlias sematopia.com *.sematopia.com sematopia.net *.sematopia.net
CustomLog /var/log/apache2/sematopia/access.log comonvhost
Then for all other VirtualHost directives, a similar line was added. Once that’s done, delete or move the old logs in /var/log/apache2. Then run:
apache2 –k restart
to restart Apache. Remember, any time you delete your log files or change your apache2.conf file restart apache.
Have a second? Check out this great Canadian Health & Living Store based in Toronto

