Django and FastCGI




Sometimes it's not possible to use Django's prefered setup (Apache & mod_python) for production servers. Either mod_python is not available, or you need some stuff which is not possible with it, so do I. I needed to access some environment variables, but mod_python removes most.



So why not use FastCGI? FastCGI is a language independent open extension to CGI that provides high performance.
So what do I need? FastCGI needs a local server, which is accessible by Apache, either using TCP/IP or Unix Sockets. There is a small script, which can start and stop the server. Use following commands to start and stop the fcgi Server.
start:	django-fcgi.py --settings=myproject.settings --host 127.0.0.1 --port 8882 --daemon

stop:	kill `ps auxww | grep [d]jango-fcgi | awk '{print $2}'`
Now you need to configure Apache.
FastCgiExternalServer /var/www/localhost/htdocs/django.fcgi -host 127.0.0.1:8882 # in httpd.conf

# and in virt host config..
RewriteEngine On
RewriteRule ^(/myapp.*)$ /django.fcgi$1 [L]
Finally give Apache a restart and your done! :-)

15. Juni, 2006

Kommentar hinzufügen