Currently, django prefers wsgi. I'm not familiar with the difference between things like fastcgi, scgi, wsgi. So can't tell the reason for now. Anyway, since a lot of ppl recommend me to try nginx for streaming web application, I'd like to give it a try. The mod_wsgi for apache is not avaible in nginx. For nginx, it has another option, uwsgi. Again, I don't know the difference. Just have a try.
To install nginx, refer to: http://wiki.nginx.org/Install
To install and set uwsgi, refere to:
http://stackoverflow.com/questions/7081462/problem-with-nginx-uwsgi-in-vhost-mode-running-django-app
http://projects.unbit.it/uwsgi/wiki/Example
My finding in the setup:
- in /etc/nginx/conf.d/default, the location can be set more simpler on top of the default setting:
server {
listen 80;
server_name 127.0.0.1;
access_log /var/log/nginx/access_log.tmp1;
location /django {
root /home/jimmy/laitao/groupbuy;
uwsgi_pass 127.0.0.1:3031;
include uwsgi_params;
}
}
The 2nd system path I add is for include django in the library path. Otherwise, uwsgi won't find the django.core.handlers.wsgi module
- To restart nginx:
sudo service nginx restart
- edit the django project wsgi configure module file. Name it as django_wsgi.py in PATH_OF_YOUR_SITE.
import os
import sys
sys.path.append('PATH_OF_YOUR_SITE')
sys.path.append('/usr/local/lib/python2.6/dist-packages')
sys.path.append('PARENT_FOLDER_OF_YOUR_SITE')
os.environ['DJANGO_SETTINGS_MODULE'] = 'YOUR_SITE.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
The 2nd sys path is for uwsgi to find the django.core.handlers.wsgi. I installed django with python 2.6. But the uwsgi is installed with python 2.7. That's the reason why uwsgi can't find the module when I run it.
- command to run uwsgi
sudo uwsgi -p 4 -s 127.0.0.1:3031 --chdir PATH_OF_YOUR_SITE --module django_wsgi
Or use the xml format in file mydjango.xml as in http://projects.unbit.it/uwsgi/wiki/Example
<uwsgi>
<socket>127.0.0.1:3031</socket>
<chdir>PATH_OF_YOUR_SITE</chdir>
<module>django_wsgi</module>
<processes>4</processes>
</uwsgi>
and run with command:
sudo uwsgi -x mydjango.xml