/ 中存储网

Nginx服务器配置支持django的uwsgi运行环境

2014-02-14 14:08:01 来源:ITJS.CN

基于nginx + uwsgi 的django部署

一、环境搭建:

1、sudo apt-get install nginx

2、sudo pip install uwsgi

debian/buntu 系统需要另行安装:

In a debian/ubuntu system you can install them with:

3、apt-get install build-essential python-dev libxml2-dev

nginx:http://nginx.com/

uwsgi: http://projects.unbit.it/uwsgi/

二、新建项目:

1、项目路径:

项目路径:/home/kevin/workspace/myproject

静态文件:/home/kevin/workspace/myproject/public

应用路径:/home/kevin/workspace/myproject/myapp

三、nginx配置:

1、sudo vim /etc/nginx/sites-enabled/default

测试配置文件:

server {

        location / {

                include uwsgi_params;

                uwsgi_pass 127.0.0.1:9090;

        }

        location /static/ {

                alias /home/kevin/workspace/myproject/public;

                autoindex on;

                allow 127.0.0.1;

                deny all;

        }

}

四、uwsgi配置: 1、django_wsgi.py import os

import sys

import django.core.handlers.wsgi

if not os.path.dirname(__file__) in sys.path[:1]:

    sys.path.insert(0, os.path.dirname(__file__))

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

application = django.core.handlers.wsgi.WSGIHandler()

2、uwsgi.xml

<uwsgi>

<chdir>/home/kevin/workspace/myproject</chdir>

<pythonpath>..</pythonpath>

<module>django_wsgi</module>

</uwsgi>

django_wsgi.py 和 uwsgi.xml 文件都放在myproject 目录下

五、启动nginx,uwsgi: 启动nginx:sudo nginx

启动uwsgi:uwsgi -s 127.0.0.1:9090 -x uwsgi.xml

五、访问: 127.0.0.1

仅此备忘

四,五部分可以省略:

uwsgi -s 127.0.0.1:9090 -M -R 2000 -p 16 --env DJANGO_SETTINGS_MODULE=settings -w "django.core.handlers.wsgi:WSGIHandler()"