in Code

How to filter logs in lighttpd

I usually don’t keep lighttpd access logs turned on to avoid writing for every read, but there are times when you need to monitor what’s going on, and you’d like to have a high signal-to-noise ratio so it might be convenient to ignore all requests to .gif, .png, .jpg, .css, .ico and other urls on your webserver.

To only log certain files, or to NOT log certain files, you resolve this the same way as you do every other thing in lighttpd… by matching lighttpd variables to regular expressions and applying the settings where they match.

[perl]
# www -> the main website
$HTTP["host"] =~ "^www.yoursite.com$" {
server.document-root = "/var/www/www.yoursite.com"
server.errorlog = "/var/log/lighttpd/www.yoursite.com/error.log"

#Only log non-css and images
<strong>$HTTP["url"] !~ "(.css|.jpg|.gif|.png|.ico)$" {
accesslog.filename = "/var/log/lighttpd/www.yoursite.com/access.log"
}</strong>
}
[/perl]

So in this example, we only log, where the URL doesn’t end with any of the “.css”, “.jpg”, “.gif”, “.png” or “.ico” extensions. We filter those out.

Hope this works for you.

Write a Comment

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Webmentions

  • Enlaces que os pueden interesar

    […] Filtrar logs en lighttpd […]