Hurley's World

  • games
  • genealogy
  • videos
  • contact
Home › Blogs › tracy's blog

Multi-Site Server Logs for Lighttpd on Ubuntu

The sites/tracy.hurleyit.com/files/img_thumbnails is not writeable

tracy — Wed, 03/05/2008 - 11:47

Sometimes, Google Analytics just isn't enough when it comes to keeping and interpreting server stats. After finding a suitable log file analyzer, AWStats, the next step involved separating out the log files on a per domain basis. When the server was first set up, everything was shuttled to one set of access and error log files. While AWStats could technically analyze this log, the suggested set up involves having one set per domain. This article details the process of separating out the log files and making sure that these new files get rotated correctly.

Create Log Directories

While it would be possible to keep all of the files in one directory and to just name them relative to the domain, for this tutorial we will assume that we will create subdirectories based on the domain name. The first step would be to create a directory for each domain.


sudo -u www-data mkdir /var/log/lighttpd/www.example1.com
sudo -u www-data mkdir /var/log/lighttpd/www.example2.com

Update lighttpd.conf

After creating the directories, it's time to update the lighttpd conf file in /etc/lighttpd. We'll want to set the log files by host name. We already had directives setting the server.document-root for these domains so we only added the bolded lines.


$HTTP["host"] =~ "(^|\.)example1.com"$" {
server.document-root = "/var/www/www.example1.com",
server.errorlog = "/var/log/lighttpd/www.example1.com/error.log",
accesslog.filename = "/var/log/lighttpd/www.example1.com/access.log",

}

$HTTP["host"] =~ "(^|\.)example2.com$" {
server.document-root = "/var/www/www.example2.com",
server.errorlog = "/var/log/lighttpd/www.example2.com/error.log",
accesslog.filename = "/var/log/lighttpd/www.example2.com/access.log",

}

After adding these directives, you will need to restart the server.

sudo /etc/init.d/lighttpd restart

Update Logrotate

Finally, we will want logrotate to rotate these new directories. Since our main goal is to integrate the logs with AWStats, it made sense to add a separate entry for each log directory. However, if you don't need call different scripts for the different domains, feel free to create one directive. We just copied the existing logrotate configuration and editted it for each of the domains. Below are examples of what this might look like.


/var/log/lighttpd/*.log {
daily
missingok
copytruncate
rotate 60
compress
notifempty
sharedscripts
postrotate
if [ -f /var/run/lighttpd.pid ]; then \
kill -HUP $( fi;
endscript
}
/var/log/lighttpd/www.example1.com/*.log {
daily
missingok
copytruncate
rotate 60
compress
notifempty
sharedscripts
postrotate
if [ -f /var/run/lighttpd.pid ]; then \
kill -HUP $( fi;
endscript
}
/var/log/lighttpd/www.example2.com/*.log {
daily
missingok
copytruncate
rotate 60
compress
notifempty
sharedscripts
postrotate
if [ -f /var/run/lighttpd.pid ]; then \
kill -HUP $( fi;
endscript
}

To make just one configuration entry, it would look like this:


"/var/log/lighttpd/*.log" "/var/log/lighttpd/www.example1.com/*.log" "/var/log/lighttpd/www.example2.com/*.log" {
daily
missingok
copytruncate
rotate 60
compress
notifempty
sharedscripts
postrotate
if [ -f /var/run/lighttpd.pid ]; then \
kill -HUP $( fi;
endscript
}

Sources

  • Lighttpd rotating log files with logrotate tool
  • Howto: Lighttpd web server setting up virtual hosting

Trackback URL for this post:

http://tracy.hurleyit.com/trackback/1140
  • lighttpd
  • logrotate
  • ubuntu
  • tracy's blog
  • Add new comment

  • @PaperlessRead Thanks! — 13 years 1 week ago
  • @Lisa03755 Thanks for the mention! — 13 years 1 week ago
  • In #drupal 7, is there a best practice for maintaining certain users across multiple drupal sites? — 13 years 29 weeks ago
  • At #mongoboston. Lots of great sessions on the schedule. — 13 years 31 weeks ago
  • @qh_murphy I hear that. I try to stay away from Windows XP for similar reasons. — 13 years 38 weeks ago
  •  
  • 1 of 17
  • ››
more

Navigation

  • Recent posts

User login

  • Create new account
  • Request new password
Connect
Sign in using Facebook

Hurley's World Community


Hurley's World on Facebook

  • games
  • genealogy
  • videos
  • contact

© Copyright 2009: Tracy Hurley