Django and SCGI
- Install scgi: I'm running Apache 2 on CentOS, so I installed the apache2 module from the tarball
- Install flup: Flup provides a bridge between some web server protocols like fastcgi, scgi, ajp, and wsgi. Django ships with a WSGI connector.
- Create a script to execute the scgi listener for my app. In my case, it was as simple as
#!/usr/bin/env python if __name__ == '__main__': from flup.server.scgi import WSGIServer from django.core.handlers.wsgi import WSGIHandler WSGIServer(WSGIHandler()).run() - Execute the app with the scgi listener. I am using runit to execute services. In this case, I run the following script
#!/bin/sh APPROOT=/home/fawad/workspace export PYTHONPATH=${APPROOT} export DJANGO_SETTINGS_MODULE=myapp.settings_modpython exec chpst -u apache:apache python /home/fawad/code/python/flup/django_scgi.py - Configure apache vhost to use this app
<IfModule !scgi_module> LoadModule scgi_module modules/mod_scgi.so </IfModule> <VirtualHost *:80> ServerName myapp.fawad.net ErrorLog /tmp/myapp_errors.log DocumentRoot /var/empty SCGIMount / 127.0.0.1:4000 </VirtualHost>
And that's it. Restart the apache server and the app should be up and running.


