Apache Access Log: don’t log static content

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, December 11, 2011

Follow me on Twitter as @mattiasgeniar

If you’re running a busy webserver on Apache, it may be interesting to prevent the access log from filling up with all the static requests on your system. You can modify the log-format so it doesn’t include all the .png, .jpg, .css, .js, … files in there.

To start, add the following into your Virtual Host config of the site where you don’t want to log static content.

SetEnvIf Request_URI "\.(txt|jpg|png|gif|ico|js|css|swf|js?.|css?.)$" StaticContent

And add the following line to the CustomLog directive where you would point to your access log.

CustomLog /var/www/site/log/access.log combined env=!StaticContent

Reload your Apache and you won’t see any static content matching the regular expression at the top to enter your logs.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.