lighttpd & django, fcgi issues

47 views
Skip to first unread message

skunkwerk

unread,
Apr 6, 2008, 5:53:59 PM4/6/08
to Django users
I'm having trouble running django with lighttpd (I'm not on a shared
host). Here is what I've installed:

ubuntu 7.10
lighttpd
flup
cmemcache
python

When I go to my web address which maps to the django project
directory, all I see is a directory listing, not any django pages.

I started fcgi like this, as in the docs:
./manage.py runfcgi method=threaded host=127.0.0.1 port=3033

have this in my lighttpd.conf:
server.modules = (
"mod_access",
"mod_alias",
"mod_accesslog",
"mod_compress",
"mod_fastcgi",
)

fastcgi.server = (
"/mnt/project/mysite.fcgi" => (
"main" => (
"host" => "127.0.0.1",
"port" => 3033,
"check-local" => "disable",
)
),
)

and the mysite.fcgi file:
#!/usr/local/bin/python
import sys,os

sys.path.insert(0,"/mnt/project")
os.chdir("/mnt/project")
os.environ['DJANGO_SETTINGS_MODULE']="settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded",daemonize="false")

I restarted lighttpd but it's still the same. If I add a 'bin-path'
to the fcgi.server I get an error when I restart lighttpd.

1) any suggestions on how to get this working?
2) my DJANGO_SETTINGS_MODULE is pointing to settings.py in my django
project, as I couldn't find any project_settings.py or anything - is
this correct?
3) for the fastcgi.server() do i need to give it the path of
the .fcgi file?

thanks

Douglas E

unread,
Apr 7, 2008, 3:38:41 PM4/7/08
to Django users
I am having the same problems and posted here. Got no response at all!
Then I started thinking maybe this is not the place to post. Perhaps
we should ask on the Lighttpd website? I have not had time yet.
Douglas

skunkwerk

unread,
Apr 7, 2008, 5:56:40 PM4/7/08
to Django users
thanks Douglas,
i guess there's something wrong with the way lighttpd and django are
connecting, because both of them are installed properly. Which means
there has to be something wrong with one or more of:

a) the start fcgi daemon command
b) lighttpd.conf
c) yourfilename.fcgi

as far as a) goes, I've tried all three sample commands without any
luck. I used netstat to see that indeed, the daemons seemed to be
running. I tried specifying a PID file with a process id number in it
(999) but it didn't seem to work as when I tried killing 999 it said
there was nothing with that pid. But seeing as how the daemons seem
to be running, I don't think this is the source of the problem.

b) in lighttpd.conf i've specified the full path to my .fcgi file, but
it doesn't seem to make a difference. lighttpd doesn't complain about
anything, and there's nothing in my lighttpd error log.

c) which leads me to believe the problem is in the .fcgi file. i have
made it executable with chmod +x, and is located in /mnt, with my
project in /mnt/project and therefore imports the paths /mnt and /mnt/
project and sets DJANGO_SETTINGS_MODULE to project.settings

when I ran ./dispatch.fcgi from the command line, I got:

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 500 INTERNAL SERVER ERROR
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
.... and a bunch of HTML

any ideas?
thanks

On Apr 7, 12:38 pm, Douglas E <magick.c...@gmail.com> wrote:

Ramiro Morales

unread,
Apr 7, 2008, 8:12:08 PM4/7/08
to django...@googlegroups.com

Why did you create the .fcgi file? As the documentation says, that file needs
to be created if you are using FastCGI through Apache and you are using
lighttpd.

What you are missing (and that's also something that is documented) is the
url.rewrite-once directive in your lighttpd configuration.

The pipeline when using lighttpd + fastcgi + apache is:

1. HTTP Request arrives to lighttpd
2. lighttpd uses the::

"^(/.*)$" => "/mysite.fcgi$1"

entry in the url.rewrite-once directive to route that request to the
mysite.fcgi location. Note mysite.fcgi file itself doesn't need to exist
it's just a ghost placeholder for the request routing. That's because of
the::

fastcgi.server."/mysite.fcgi"."main"."check-local" => "disable"

setting.

(note also thaat you need to correct that "/mnt/project/mysite.fcgi"
entry because it doesn't match "/mysite.fcgi$1". they should.

3. lighttpd's mod_fastcgi module gets the request and routes it via a TCP or
Unix socket to thegastCGi server

4. The fastCGI server (in your case Django's manage.py runfastcgi + flup) gets
the request

Regards,

--
Ramiro Morales

skunkwerk

unread,
Apr 7, 2008, 10:12:27 PM4/7/08
to Django users
thank you so much Ramiro,
I've removed the .fcgi file. the problem turned out to be that the
url.rewrite part of the configuration was in my original setup, but
was producing a warning and was being ignored because I hadn't
uncommented the mod_rewrite module in lighttpd.conf

it's working now!

is it normal for the fcgi start command to start 4 processes (as seen
in htop)? in addition, it didn't start the processes with the correct
pid that i specified in a file...

thanks

On Apr 7, 5:12 pm, "Ramiro Morales" <cra...@gmail.com> wrote:

Douglas E

unread,
Apr 8, 2008, 1:54:49 AM4/8/08
to Django users
So then I have but mine is still not working. Maybe it is a problem
with my url.rewrite-once or including rewrite which you do not have
listed??
Thanks for any help!

Douglas

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


server.document-root = "/var/www"
#$HTTP["host"] == "journeytothestars.webhop.net"{server.document-root
= "/var/www/"}

fastcgi.server = (
"/journeysite.fcgi" => (
"main" => (
# Use host / port instead of socket for TCP fastcgi
"host" => "127.0.0.1",
"port" => 3080,
#"socket" => "/home/user/mysite.sock",
"check-local" => "disable",
)
),
)
alias.url = (
"/media/" => "/home/douglas/django_trunk/django/contrib/admin/media/",
)

url.rewrite-once = (
"^/$" => "/index.html",
".*/images.*" => "$0",
".*\.css" => "$0",
"^(/media.*)$" => "$1",
".*\.html($|\?)" => "$0",# This will make mod_rewrite "ignore" all
requests of html files (or rather rewrite them to themselves, which
makes it effectively ignore them)
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/.*)$" => "/journeysite.fcgi$1",
)
Reply all
Reply to author
Forward
0 new messages