Nginx + uwsgi + django 配置


1. 安装nginx
sudo -s
add-apt-repository ppa:nginx/stable
apt-get update 
apt-get install nginx


2. 安装uwsgi
sudo apt-get install python-dev libxml2 libxml2-dev python-pip
pip install http://projects.unbit.it/downloads/uwsgi-latest.tar.gz


Ubuntu 10.04/10.10
sudo apt-get install libxml2-dev python-pip python2.6-dev
sudo pip install http://projects.unbit.it/downloads/uwsgi-latest.tar.gz


Ubuntu 11.04/11.10
sudo apt-get install libxml2-dev python-pip python2.7-dev
sudo pip install http://projects.unbit.it/downloads/uwsgi-latest.tar.gz


apt-get install  uwsgi-core uwsgi-plugin-python
update-alternatives --config uwsgi-plugin-python


3. Django 配置
在/home/bolewang/workspace/SignServer/signserver 目录下
1) 丢一个wsgi文件到signserver目录下,即/home/bolewang/workspace/signserver 下面


#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os


sys.path.append(os.path.abspath(os.path.dirname(__file__)))
# 下面这行是mysite的父目录
sys.path.append('/home/bolewang/workspace/SignServer')
# 下面这行的值请改成相应项目名称.settings
# 我们这里是signserver.settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'signserver.settings'


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


2) 修改uwsgi配置文件、
在signserver 目录下面
cat > www.ini << EOF
[uwsgi]
socket=127.0.0.1:8888
chmod-socket=666
processes=6
max-request=2000
memory-report=true
enable-threads=true
pythonpath=/home/bolewang/workspace/SignServer
chdir=/home/bolewang/workspace/SignServer/signserver
module=signserver.wsgi:application
wsgi-file=/home/bolewang/workspace/SignServer/signserver/wsgi.py
EOF


然后利用uwsgi --ini www.ini 命令运行,启动uwsgi服务,或者利用
invoke-rc.d uwsgi restart 重启 uwsgi服务.


3) 修改nginx配置文件
进入/etc/nginx/sites-enabled/ 目录下面, 修改default 文件
cat > /etc/nginx/sites-enabled/default << EOF
server {
listen   8080; ## listen for ipv4; this line is default and implied
#listen   [::]:80 default_server ipv6only=on; ## listen for ipv6


server_name localhost;


location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8888;
}


    location /media/ {
        alias /home/bolewang/workspace/SignServer/signserver/media/;
autoindex on;
allow 127.0.0.1;
        allow ::1;
        deny all;
    }
}


EOF


启动nginx 服务
sudo service nginx  start/restart


然后试下访问127.0.0.1:8080


备注:
1. apk太大,nginx会提示一个401的错误,提示文件too large, 在/et/nginx目录下面,找到nginx.conf文件,在http域内,添加
  #restrict max upload size
  client_max_body_size 30M;
就OK了。


2. 修改多域名可以参照
http://www.howtocn.org/nginx:server_name_how_to
修改/etc/nginx/site-enables/default 


参考:
http://wangye.org/blog/archives/570/
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/uwsgi/
http://blog.csdn.net/feng88724/article/details/7258325

你可能感兴趣的:(Nginx + uwsgi + django 配置)