Category: lighttpd

  • lighttpd

    lighttpd is a lightweight web server used mainly to serve static files. Youtube used lighttpd before it was purchased by Google. I was using lighttpd with some file hosting/image hosting sites with mod_secdownload that allows the link to expire after a predefined time.

    To install Lighttpd on CentOS, run

    yum install lighttpd
    

    To see lighttpd version, run

    lighttpd -v
    
  • lighttpd mod alias

    mod_alias lighttpd module allow you to map urls to file system. For example, you need /mrtg show /var/www/mrtg

    You need to first enable mod_alias in lighttpd.conf

    vi /etc/lighttpd/lighttpd.conf
    

    Find

    server.modules              = (
    #                               "mod_rewrite",
    #                               "mod_redirect",
    #                               "mod_alias",
    

    and remove the comment # on “mod_alias” line. It should look like

    server.modules              = (
    #                               "mod_rewrite",
    #                               "mod_redirect",
                                    "mod_alias",
    

    To add alias, add following in lighttpd.conf

    alias.url = ( "/mrtg/" => "/var/www/mrtg/" )
    

    If you need to add more, just use

    alias.url += ( "/cgi-bin/" => "/var/www/cgi-bin/" )
    

    Alias will allow you to access files/programs in the folder with url http://yourdomain-or-ip/mrtg/

    See Lighttpd

  • bind lighttpd to one ip address

    I want to bind lighttpd on IP address 76.76.18.20, so i can use other IP’s for Apache, Apache have “Listen” option to bind apache to specific IP address.

    vi /etc/lighttpd/lighttpd.conf
    

    Find

    #server.bind                = "127.0.0.1"
    

    Replace with

    server.bind                = "76.76.18.20"
    

    See lighttpd

  • Auto restart lighttpd on crash

    To restart lighttpd if it went down or crashed, create a file check_lighttpd.sh

    mkdir /usr/serverok
    vi /usr/serverok/check_lighttpd.sh
    

    With the following content

    #!/bin/bash
    
    /usr/bin/wget --tries=1 --timeout=30 -O /dev/null http://localhost:80/up.html
    
    if [ $? -ne 0 ]; then
    (
    killall -9 lighttpd;
    killall -9 gam_server;
    killall -9 php-cgi;
    /etc/init.d/lighttpd stop;
    mv /var/log/lighttpd/access.log /var/log/lighttpd/access.$(date +%Y%m%d_%H).log
    mv /var/log/lighttpd/error.log /var/log/lighttpd/error.$(date +%Y%m%d_%H).log
    /etc/init.d/lighttpd start;
    echo 'restarting lighttpd' `ps aux` | mail -s "`hostname` restarting lighttpd `who | awk '{print $6}'`" [email protected]
    datetime=`date "+%Y%m%d %H:%M:%S"`
    echo $datetime "failure">>/var/log/lighttpd/check.log
    )
    fi
    
    

    Make it executable

    chmod 755 /usr/serverok/check_lighttpd.sh
    

    Create a file up.html on web root of your web site

    echo "up" > /path/to/docroot/up.html
    

    Now set a cronjob to run every 5 minutes

    crontab -e
    

    Add following cronjob

    */5 * * * *  /usr/serverok/check_lighttpd.sh  1> /dev/null 2> /dev/null
    

    See lighttpd