Lighttpd + FCGI settings

lighttpd

I have decided to change my projects server backend from Apache+WSGI to lighttpd+FCGI.
Now, everything work fine, except one annoying problem with DOCUMENT_URI, that receives my django server (started as ./manage.py runfcgi … ). It’s always contains /index.fcgi prefix!

Let’s have a look on my lighttpd conf:

fastcgi.server = (
    ".fcgi" => (
        "localhost" => (
            "host" => "127.0.0.1",
            "port" => 3033,
            "check-local" => "disable",
        )
    ),
)

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

According to rewrite rule, http://www.mysite.com/procucts/ request will be changed by mod_rewrite to ….mysite.com/index.fcgi/procucts/, consequently DOCUMENT_URI will be: index.fcgi/procucts/.

But, when I used to work with WSGI on Apache my DOCUMENT_URI does not contains handler script name.

My Apache WSGI settings:

WSGIScriptAlias / /path/to/my/site/index.wsgi

Please give me an advice!

Best Answer

Have a look at http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/

I followed that to get my Lighttpd + FastCGI setup working (I've included a sanitised verison of my config below for reference). You will also want to set FORCE_SCRIPT_NAME="" in your settings.py.

server.modules   += ( "mod_fastcgi" )
server.modules   += ( "mod_alias" )

$HTTP["host"] =~ "(www\.)?domain\.com" {
    fastcgi.server = (
        "/django.fcgi" => (
            "main" => (
                "host" => "127.0.0.1",
                "port" => 3000,
                "check-local" => "disable",
            )
        ),
    )

    alias.url = (
        "/admin-media" => "/path/to/django/contrib/admin/media/",
    )

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