nginx + uwsgi + django


一、django + uwsgi 安装

安装python 扩展库(大部分系统已安装)

yum install zlib zlib-devel

yum install sqlite3


python 安装

python下载安装

wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz


django安装

django下载安装:

wget https://www.djangoproject.com/download/1.6.11/tarball/


setuptools安装

setuptools下载安装:

wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-12.0.3.tar.gz


uwsgi安装

uwsgi下载安装:

wget http://projects.unbit.it/downloads/uwsgi-2.0.6.tar.gz


python-mysqldb安装

安装mysql开发包:

yum install mysql mysql-devel -y

pip install mysql-python


二、uwsgi 启动

1、选择django工作目录

cd  /data/scripts

django-admin.py startproject weidian


2、配置uwsgi.ini

网上很多给的配置都不能自动加载,而且进程会主动退出。下面的配置可以解决这个问题

cat  uwsgi.ini

[uwsgi]

socket = 127.0.0.1:8084

processes = 2

chdir = /data/scripts/weidian/weidian 

pythonpath = ..

env = DJANGO_SETTINGS_MODULE=weidian.settings     #指定django settings

module = django.core.handlers.wsgi:WSGIHandler()    

daemonize = /data/scripts/weidian/logs/uwsgi.log   #守护进程

py-autoreload = 1       #自动加载

3、启动uwsgi

uwsgi  uwsgi.ini


三、nginx配置与启动

1、nginx配置

   server {

        listen 8083;

        server_name 10.3.1.202 idc03-ms-ns-02;

        location / {

            include uwsgi_params;

            uwsgi_pass 127.0.0.1:8084;

            access_log /data/sever/nginx-dav/logs/uwsgi_access.log main;

        }

        error_page 500 502 503 504 /50x.html;

        location = /50x.html {

            root /data/sever/nginx-dav/html;

        }

     }


2、启动或加载nginx

nginx -s reload


四、访问

根据你的django url配置,定制相应的访问页面

http://10.3.1.202:8083/???