Lighttpd add expire and cache-control headers

For static content like image we can add expire headers in lighttpd.

There are two ways to add expire headers.

  1. with expire.url
  2. with setenv.add-response-header

Add any of following configuration in lighttpd.conf and restart after adding.

With expire.url:

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

In some versions of lighttpd above rule wont works, in that case use setenv.add-response-header to set expire interval.

With setenv.add-response-header:

$HTTP["url"] =~ "\.(jpg|gif|png|css|js|txt|ico)$" {
    setenv.add-response-header = ( "Cache-Control" => "max-age=290304000, public" )



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s