The way to enable django + uwsgi + nginx

2 篇文章 0 订阅
1 篇文章 0 订阅

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;
       }
}


os.environ['DJANGO_SETTINGS_MODULE'] = 'groupbuy.settings'import django.core.handlers.wsgiapplication = django.core.handlers.wsgi.WSGIHandler()

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 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值