- Edit conf file: /etc/lighttpd/lighttpd.conf
- Enable mod_expire and mod_compress.
- Expire static files set for 3 days:
$HTTP["url"] =~ "\.(js|css|gif|jpg|png|ico|txt|swf|html|htm)$" { expire.url = ( "" => "access 3 days" ) }
- Compress mime types:
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype ; ; = ("text/plain", "text/html", "text/css", "text/xml", "text/javascript")
- Cleanup the compressed cache via daily cron script:
#!/bin/bash
# lighttpd_cache_clean
# Clean cache stored at /var/cache/lighttpd/compressr /># Place in /etc/cron.daily
# Cache dir path
CROOT="/var/cache/lighttpd/compress"
#Deleting files older than 3 days
HOURS=72
# Lighttpd user and group
LUSER="lighttpd"r />LGROUP="lighttpd"<br />
# start cleaning
/usr/sbin/tmpwatch --mtime ${HOURS} ${CROOT}
# if directory missing just recreate it
if [ ! -d $CROOT ]
then
mkdir -p $CROOT
chown ${LUSER}:${LGROUP} ${CROOT}
fi
exit 0
- Create the cache directory and update permissions:
mkdir -p /var/cache/lighttpd/compressr />chown lighttpd:lighttpd /var/cache/lighttpd/compress
- Restart lighttpd.