Walk-around should ofcourse be workaround but it feels more like a walk around …
Today I ‘moved’ the first version of my application from the Django development setup (run via “./manage runserver”) to a lighttpd/fcgi production setup. Been cleaning up code and concluded I wanted the app straight on the ‘/’ or docroot with a simple config like this:
HTTP["host"] == "example.int" {
fastcgi.server = (
"/" => (
"main" => (
"host" => "192.168.1.2",
"port" => 8000,
"check-local" => "disable",
#"fix-root-scriptname" => "enable",
)
),
)
}
After a lot of messing around and not getting the aformetioned setup to work I found the ‘PATH_INFO’ problem. The easiest way is to have lighttpd version 1.4.23 running, because then you can enable:
"fix-root-scriptname" => "enable",
And therewith actually acces your app on “/” instead of “/dd” as shown in the below example under the line with “fastcgi.server (“.
The problem however is that lighttpd version 1.4.23 is not apt-get-able yet and I like my systems clean. So here’s the somewhat cumbersome but functional example that works:
HTTP["host"] == "example.int" {
fastcgi.server = (
"/dd" => (
"main" => (
"host" => "192.168.1.2",
"port" => 8000,
"check-local" => "disable",
)
),
)
url.rewrite-once = (
"^(/.*)$" => "/dd/$1",
)
}
What happens is that lighttpd passes an incoming request like “/url_to_something” to your fcgi proces, but fcgi is on “/dd/url_to_something”. So with the rewrite rule we make sure the “/dd” prefix is added, other wise it would not be passed to the fcgi handler.
The problem however is that you should modify all your in-app links so they would be prefixed with /dd otherwise you end up with a 404. This can be globally resolved by adding the line below to your Django settings.py
FORCE_SCRIPT_NAME = ""
Django then strips of the “/dd” prefix just before it gets parsed by your django app URL Dispatcher.
So when lighttpd version 1.4.23 is in the debian and/or Ubuntu repository, you apt get it and adjust your setup in 3 places.
Remove the rewrite rule and the “dd” part from your lighttpd host config and disable the FORCE_SCRIPT_NAME in your settings.py. Doing it like this keeps everything running with the least adjustments now and only a little work to be done in the near future.
