views:

1297

answers:

2

I've got lighttp configured to start and serve django via fastcgi on ubuntu. When I have only a single site enabled (via ubuntu's apache-like conf-available, conf-enabled mechanism), everything runs beautifully. When I enable a second site, my url rewrites seem to stop working correctly, though the fcgi processes are started and serving data. Here's my configuration:

conf-available/10-example.conf

$HTTP["host"] == "example.com" {
    var.virt_name = "example"
    include "includes/incl-fastcgi.conf"
}

includes/incl-fastcgi.conf

global {
    server.modules += ("mod_rewrite",
                "mod_fastcgi")
}

var.site_folder = "/" + virt_name
var.site_root = server_root + site_folder
var.socket = server_root + "/.handles/" + virt_name + ".socket"
server.document-root = site_root

fastcgi.server = (
    "/django.fcgi" => (
        "main" => (
            "socket" => socket,
            "bin-path" => "/etc/lighttpd/scripts/fcgi.sh",
            "bin-environment" => ( "VIRT" => virt_name, ),
            "check-local" => "disable",
            "min-procs" => 1,
            "max-procs" => 1,
            "allow-x-send-file" => "enable",
        ),
    ),
)

alias.url = (
    "/media/admin" => "/usr/share/python-support/python-django/django/contrib/admin/media", #why the hell does it live here?
)

url.rewrite-once = (
    "^(/media.*)$" => "$1",
    "^/favicon\.ico$" => "/media/favicon.ico",
    "^/robots\.txt$" => "/robots.txt",
    "^(/.*)$" => "/django.fcgi$1",
)

When I enable the second site, everything is identical except that now there's a second link to a (slightly modified) copy of 10-example.conf in conf-enabled. When this happens, my sites fail with this django-served error:

Page not found (404)
Request Method:     GET
Request URL:    http://example.com/django.fcgi/[the url I requested]

I'm not sure why enabling another site should break the existing setup. I believe the host-based syntax should isolate any changes to that specific host, but it does not seem to be the case.

+2  A: 

In case anyone in the future looks at this question, I believe the answer was that it's fixed in version 1.4.20 or later and the server was running v1.4.19 since that's what Ubuntu's repository had.

Gabriel Hurley
+1  A: 

Did you set FORCE_SCRIPT_NAME to "" in settings.py?

FORCE_SCRIPT_NAME=""
jpic
Yeah, that had no effect.
Paul McMillan
Keep it there because that's actually required anyway ;)
jpic
That worked for me! Thanks!
Edu Felipe
It's not actually required anymore if the rest of your settings are properly configured.
Paul McMillan