I use the following directory hierarchy: /home/germ/web/projects/{admin-media,django,media,templates}/test1 (where test1 is the project name)

For all Django projects that don't have their own admin media:

ln -s /home/germ/django/trunk/django/contrib/admin/media /home/germ/web/projects/admin-media/myproject

In addition I put all project names in /etc/hosts so that I can access http://test1.localhost:8000/

127.0.0.1 localhost test1.localhost

It's a pain to tack on :8000 to the hostname everytime that I want to access the web site, so I use the following iptables, which redirects all traffic going to 127.0.0.1 on port 80 to port 8000:

iptables -t nat -I OUTPUT --src 0/0 --dst 127.0.0.1 -p tcp --dport 80 -j REDIRECT --to-ports 8000

I have decided to use lighttpd and fastcgi. I am doing so by applying JCrasta's patch to the trunk.

Here's my lighttpd.conf file:


# /etc/lighttpd/lighttpd.conf
# lighttpd configuration file

server.port = 8000
server.username = "lighttpd"
server.groupname = "lighttpd"
server.pid-file = "/var/run/lighttpd.pid"

server.modules = ( "mod_rewrite", "mod_redirect", "mod_alias",
                   "mod_access", "mod_fastcgi", "mod_accesslog" )

accesslog.filename = "/var/log/lighttpd/access.log"
server.errorlog = "/var/log/lighttpd/error.log"
server.indexfiles = ( "index.html" )

mimetype.assign = (
  ".css"  => "text/css",
  ".gif"  => "image/gif",
  ".html" => "text/html",
  ".jpeg" => "image/jpeg",
  ".jpg"  => "image/jpeg",
  ".js"   => "text/javascript",
  ".pdf"  => "application/pdf",
  ".png"  => "image/png",
  ".txt"  => "text/plain"
)

var.web_root = "/home/germ/web"

server.document-root = var.web_root + "/misc"

include_shell "cat /etc/lighttpd/hosts-enabled/*"

And here's the virtual host config for lighttpd.conf (I chose not to do simple-vhost, because I didn't find it appropriate for my directory structure and naming).


# /etc/lighttpd/hosts-enabled/test1.localhost (a symlink
#  /etc/lighttpd/hosts-available/test1.localhost)
$HTTP["host"] == "test1.localhost" {
  server.document-root = var.web_root + "/projects/django/test1"

fastcgi.server = ( "/test1.fcgi" =>
    ( "main" =>
      (
        "socket" => "/var/www/sockets/germ/test1.sock",
        "check-local" => "disable",
      )
    )
  )

alias.url = (
    "/media/" => var.web_root + "/projects/media/test1/",
    "/admin-media/" => var.web_root + "/projects/admin-media/test1/",
  )

url.rewrite-once = (
    "^(/media.*)$" => "$1",
    "^(/admin-media.*)$" => "$1",
    "^/favicon.ico$" => "/media/favicon.ico",
    "^(/.*)$" => "/test1.fcgi$1",
  )
}

Run your python project with python manage.py runfcgi daemonize=false socket=/var/www/sockets/germ/test1.sock

And point your browser to http://test1.localhost/ and BAM!