CentOS 5.5 + Nginx 0.8.50 + uwsgi + Django 1.2.3 部署django

软件支持与安装

# wget http://ftp.exim.llorien.org/pcre/pcre-8.00.tar.gz   (平台支持)

# tar xzvf pcre-8.00.tar.gz

# cd pcre-8.00

# ./configure

# make && make install

# wget http://nginx.org/download/nginx-0.8.50.tar.gz

# tar xzvf nginx-0.8.50

# cd nginx-0.8.50

# ./configure  (后面的参数可根据需求自行设定)

# make && make install

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

# tar xzvf uwsgi-0.9.6.2.tar.gz

# cd uwsgi-0.9.6.2

# make

# cp uwsgi /usr/bin

(此处不介绍如何安装Python,django,mysql-python)

这里平台和所有软件都安装完毕后,下面就开始来配置了:

<配置部分>

涉及nginx的配置有两个文件: nginx.conf   django_uwsgi.conf(连接django与nginx)

nginx.conf里面的配置很简单,只需要一句话:

http{  ...

include    django_uwsgi.conf

....}

django_uwsgi.conf文件配置如下:

# Django project 
server { 
        listen  80; 
        server_name first.domain.com; 
 
          location / { 
            uwsgi_pass   127.0.0.1:9000; 
            include     uwsgi_params; 
            access_log  off;  }

接着是uwsgi.xml的配置

# mkdir -p /home/uwsgi;cd /home/uwsgi

# vim uwsgi.xml

<uwsgi> 
  <socket>127.0.0.1:9000</socket> 
  <listen>200</listen> 
  <master>true</master> 
  <pidfile>/usr/local/nginx/uwsgi.pid</pidfile> 
  <processes>8</processes> 
  <pythonpath>/opt/www/first</pythonpath>  #此处为django项目的目录
  <pythonpath>/opt/www/</pythonpath> 
  <module>django_wsgi</module> 
  <profiler>true</profiler> 
  <memory-report>true</memory-report> 
  <enable-threads>true</enable-threads> 
  <logdate>true</logdate> 
  <limit-as>6048</limit-as> 
  <daemonize>/opt/www/logs/django.log</daemonize> 
</uwsgi>

创建应用模块:

# cd /opt/www/first         #django项目

# vim django_wsgi.py

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


到这里,一切都配置完毕,启动服务:

# uwsgi -x /home/uwsgi/uwsgi.xml

# /usr/local/nginx/sbin/nginx

相关推荐