Lighttpd mod_expire

If you have checked your page with google pagespeed and you have got warning about
Leverage Cache Browsing and you’re using Lighttpd instead of Apache, here is how to
enable it with mod expire.

We have to edit lighttpd config /etc/lighttpd/lighttpd.conf. First we enable mod_expire
in server.modules section and we add some lines about witch type of files we want to cache longer to mod_expire section.And at the end we enable etags.

server.modules              = (
...

#                               "mod_usertrack",
                                "mod_expire",
#                               "mod_rrdtool",
                                "mod_accesslog" )
...

#### mod_expire
$HTTP["url"] =~ "\.(png|js|jpg|gif|ico|css)$" {
expire.url = ( "" => "access 21 days" )

...

####etag
etag.use-inode = "enable"
etag.use-mtime = "enable"
etag.use-size = "enable"
static-file.etags = "enable"

Now we can restart lighhtpd service lighttpd restart and check if mod_expire works correctly.

#curl -I http://www.mypage.test/test/light.jpg
HTTP/1.1 200 OK
Expires: Sun, 19 Feb 2012 21:56:11 GMT
Cache-Control: max-age=3456000
Content-Type: image/jpeg
Accept-Ranges: bytes
ETag: "-649924182"
Last-Modified: Wed, 04 Jan 2012 15:27:27 GMT
Content-Length: 3538
Date: Tue, 10 Jan 2012 21:56:11 GMT
Server: lighttpd/1.4.26

Leave a comment