lighttpd

disable logging of images in access log

Apache:

SetEnvIfNoCase Request_URI "\.(gif|jpe?g|png|htc|css|js|ico)$" skiplog
CustomLog "/var/log/httpd/access.log" combined env=!skiplog

Lighttpd:

$HTTP["url"] =~ "\.(gif|jpe?g|png|htc|css|js|ico)$" {
  accesslog.filename = "/dev/null"
}

lighttpd redirect to external url if file not found

Below is a rewrite/redirect rule using url.rewrite-[repeat]-if-not-file similar to Apaches' "!-f" RewriteRule.

# Redirect to external url if image file not found
url.rewrite-if-not-file = ( "^\/images\/.*\.jpg$" => "/redirect$0" )
url.redirect = ( "^\/redirect\/(.*)$" => "http://other.domain.tld/$1" )

Deny access to .htaccess files in lighttpd

In lighttpd you can use mod_access to deny files starting with a certain expression, such as hidden dot files. (example: .htaccess or .svn)

# Deny access to hidden files
$HTTP["url"] =~ "/\." {
    url.access-deny = ("")
}

Munin stats for apache and lighttpd

Get status of apache (80) and lighttpd (81) on different ports:

This is done at the nodes.

  1. Enable apache server-status in httpd.conf :
    <Location /server-status> 
        SetHandler server-status
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Location>
  2. Enable lighttpd server-status in lighttpd.conf :
    $HTTP["remoteip"] == "127.0.0.1" {
    status.status-url          = "/server-status"
    }
  3. Create /etc/munin/plugin-conf.d/apache:
    [apache*]
    env ports="80 81" 

    * Test with:

    ports="80 83" /etc/munin/plugins/apache_processes

lighttpd idle process will be a straight line as total of busy and idle process is always the same when drawn as STACK, . To change this to LINE1:

At the host, edit "/etc/munin/munin.conf" and add the below line to the corresponding host:

apache_processes.idle81.draw LINE1

Lighttpd client side optimization

  1. Edit conf file: /etc/lighttpd/lighttpd.conf
  2. Enable mod_expire and mod_compress.
  3. Expire static files set for 3 days:
    $HTTP["url"] =~ "\.(js|css|gif|jpg|png|ico|txt|swf|html|htm)$" { expire.url = ( "" => "access 3 days" ) }
  4. Compress mime types:
    compress.cache-dir         = "/var/cache/lighttpd/compress/"
    compress.filetype          = ("text/plain", "text/html", "text/css", "text/xml", "text/javascript")
  5. Cleanup the compressed cache via daily cron script:
    #!/bin/bash
    # lighttpd_cache_clean
    # Clean cache stored at /var/cache/lighttpd/compress
    # 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"
    LGROUP="lighttpd"

    # 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
  6. Create the cache directory and update permissions:
    mkdir -p /var/cache/lighttpd/compress
    chown lighttpd:lighttpd /var/cache/lighttpd/compress
  7. Restart lighttpd.

Syndicate content
Comment