Adding domains to apache access logs

A useful tweak for when multiple domains share a log file

If you’re managing a VPS with multiple apache vhosts, the default configuration records access to each vhost in the same log file. This gives you access logs that look like the following, which makes it hard to tell which site is being accessed.

Screen Shot 2016-03-06 at 7.53.19 PM

Adding the domain name to each entry in the access.log file

To get started, SSH into your server and pull up the apache2.conf file.

sudo nano /etc/apache2/apache2.conf

I’m working on a ubuntu server, so your config files and logs might be stored in different locations than mine.

You’ll want to scroll down to find the LogFormat entries. If you’re using nano, you can press ctrl + w and then type “logformat” (without the quotes) and press enter to jump to the proper location.

Next you’ll add %{Host}i to the beginning of each line. I’ve personally added SITE at the beginning as well to help differentiate each log entry while scanning through the access log.

Screen Shot 2016-03-06 at 7.49.54 PM

After making these updates, save the file (ctrl + x, and press “y” then the enter key in nano) and reload apache.

sudo service apache2 reload

You can now tail your access log and see that the domain names are now recorded along with each entry.

tail -f /var/log/apache2/access.log

Screen Shot 2016-03-06 at 7.51.08 PM

You can read more about the LogFormat options in the apache docs at: