Deploying Snowy with Lighttpd

Introduction

If you are running your own server, you may wish to deploy Snowy using Lighttpd using fastcgi. This guide is intended to help you do just that. I used the following guide:

Many thanks to SandyArmstrong and Jeff for helping me out in IRC!

Prerequisites

You need to already have lighttpd and fastcgi installed and properly configured.

A few packages that are required

  • Lighttpd
  • flup
  • Django
  • Everything listed in the INSTALL file

I'm also assuming that since you run your own server, you've already tested your Snowy install using the Django test server (manage.py runserver), followed the instructions in INSTALL, etc.

Setup

Fastcgi connects to the django app though a socket. Therefore, django needs to create the socket and then lighttpd's fastcgi needs to connect to the socket.

Save this file as startSnowy.sh The location does not matter much, in this example the location will be /home/http/snowy/startSnowy.sh

startSnowy.sh

# Replace these three settings.
PROJDIR="/home/http/snowy"
PIDFILE="$PROJDIR/snowy.pid"
SOCKET="$PROJDIR/snowy.sock"

cd $PROJDIR
if [ -f $PIDFILE ]; then
    kill `cat -- $PIDFILE`
    rm -f -- $PIDFILE
fi

exec /usr/bin/env - \
    PYTHONPATH="../python:.." \
   ./manage.py runfcgi socket=$SOCKET pidfile=$PIDFILE

Issue proper permissions (ex: chmod 775 startSnowy.sh)

Add the following to your lighttpd.conf

  $HTTP["host"] =~ "snowy.example.net" {
        server.document-root="/home/http/html/"
        accesslog.filename = "/var/log/lighttpd/access-snowy.log"
        server.name     =       "snowy.example.net"
        
        fastcgi.server = (
                "/snowy.fcgi" => (
                "main" => (
                "socket" => "/home/http/snowy/snowy.sock",
                "check-local" => "disable",
                )       
                ),
        )

        alias.url = (
                "/site_media" => "/home/http/snowy/site_media/",
                "/media" => "/usr/lib/python2.6/site-packages/django/contrib/admin/media/",
        )

        url.rewrite-once = (
                "^(/site_media.*)$" => "$1",
                "^(/media.*)$" => "$1",
                "^(/.*)$" => "/snowy.fcgi$1",
        )

  }

Make sure to change socket, site_media, media, and the other parameters accordingly.

Add FORCE_SCRIPT_NAME = '' to local_settings.py.
This prevents urls from being written as http://snowy.example.net/snowy.fcgi/blah. Instead they will be written as http://snowy.example.net/blah

Restart or Reload lighttpd

Run startSnowy.sh as the web server user
Example (as root): su -c '/home/http/snowy/startSnowy.sh' http

Now go to the server and see if snowy loads: ex: http;//snowy.example.net/

If using SSL Remember to add to the local_settings.py file the following directive: URI_SCHEME = 'https'

You may want to add startSnowy.sh to /etc/rc.local or to a similar file so it starts and creates the socket when your server boots.
Ex: su -c '/home/http/snowy/startSnowy.sh' http &

Notes/Troubleshooting

Snowy 0.2

Projects/Snowy/Install/Lighttpd (last edited 2013-11-22 20:53:50 by WilliamJonMcCann)