一.安装uwsgi
1.到http://projects.unbit.it/uwsgi/wiki/WikiStart#Getit 下载最新版本的uwsg。
安装python-devel
2.python uwsgiconfig.py --build
python setup.py install
yum install python-setuptools
wget http://nginx.org/nginx.tar.zg
groupadd www
useradd -g www www
二、安装nginx
yum install pcre-devel
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module
make
make install
三、安装django
tar xzvf Django-1.4.3.tar.gz
cd Django-1.4.3
sudo python setup.py install
nginx配置
location / {
   include uwsgi_params;
   uwsgi_pass 127...1:9090;
}
新建一文件
vi myapp.py
def application(environ, start_response):
 start_response('200 OK', [('Content-Type', 'text/plain')])
 yield 'Hello World\n'
启动uwsgi:
uwsgi -s 127.0.0.1:9090 -w myapp
可以访问啦!可以看到浏览器打印:Hello World
说明:这里只是用uwsgi做的App,还未使用django框架。
//新建一项目
//mkdir -p /www
//cd /www
//django-admin.py startproject oa
python manage.py runserver 0.0.0.0:8080 启动django自带的简单web server
浏览器中输入http://ip:8080将打开django页面。但是,此时还未使用nginx服务器
创建一个mysite/mysite/views.py
from django.http import HttpResponse
def hello(request):
   return HttpResponse("Hello world")
更改urls.py
from django.conf.urls import patterns, include, url
from mysite.views import hello
urlpatterns = patterns('',
   ('^hello/$', hello),
)
浏览器中http://ip:8080/hello/
将得到hello页面。这是第一个django实例
使用uwsgi跑django
cat django.ini
[uwsgi]
# set the http port
http = :9090
#socket = 127.0.0.1:9090
#socket = /tmp/socket
master = true
processes = 4
chdir = /www/mysite
# load django
module = mysite.wsgi

#新版本,找不到上面那个文件时用这行代码wsgi-file =  myproject/wsgi.py
buffer-size = 65535
uwsgi --ini django.ini
浏览器中http://ip:9090/hello/ 可以访问了,这是使用uwsgi跑django
(注:
[uwsgi]
chdir=/path/to/your/project
module=mysite.wsgi:application
master=True
pidfile=/tmp/project-master.pid
vacuum=True
max-requests=5000

daemonize=/var/log/uwsgi/yourproject.log

uid = www

gid = www

--socket=127.0.0.1:49152 \ # can also be a file

--processes=5 \ # number of worker processes
--uid=1000 --gid=2000 \ # if root, uwsgi can drop privileges
--harakiri=20 \ # respawn processes taking more than 20 seconds
--limit-as=128 \ # limit the project to 128 MB
--max-requests=5000 \ # respawn processes after serving 5000 requests
--vacuum \ # clear environment on exit
--home=/path/to/virtual/env \ # optional path to a virtualenv
--daemonize=/var/log/uwsgi/yourproject.log # background the process
reload:
 
    

# using kill to send the signalkill -HUP `cat /tmp/project-master.pid`# or the convenience option --reloaduwsgi --reload /tmp/project-master.pid


stop:
kill -INT `cat /tmp/project-master.pid`# or for convenience...uwsgi --stop /tmp/project-master.pid
)
nginx + uwsgi + django
将上面的http注释掉,改为socket = 127.0.0.1:9090
用http是不行的,我这个调试了很久,郁闷~
nginx配置
location / {
   include uwsgi_params;
   uwsgi_pass 127.0.0.1:9090;
}
浏览器中输http://ip/hello/成功访问
http://djangobook.py3k.cn/2.0