0

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!

1 Answers1

0

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",
    )
}
rodjek
  • 3,297
  • 16
  • 14
  • FORCE_SCRIPT_NAME, YES! That was my solution, god bless you rodjek! –  Aug 18 '09 at 03:23
  • FORCE_SCRIPT_NAME is a hack to work around fact that fastcgi/flup and mod_python don't always get SCRIPT_NAME correct. The mod_wsgi module on the other hand always gets SCRIPT_NAME correct. I guess the question is why you need to change away from Apache/mod_wsgi in the first place as other options don't provide anything better. – Graham Dumpleton Aug 20 '09 at 11:07