简述uWSGI+Nginx+Python 搭建过程

由于服务器上面的Python和Nginx都已经安装完毕,咱们就直接叙述uWSGI的安装,对照各方面的测试数据uWsgi在性能方面相对其他方式还是比较不错的!他是一个快速的、纯C语言开发的、自维护的、对开发者或是系统管理员友好的应用程序服务器。

官方网址:http://projects.unbit.it/uwsgi/

文档地址:http://projects.unbit.it/uwsgi/wiki/Doc

准备

cd /usr/local
wget http://projects.unbit.it/downloads/uwsgi-1.0.2.1.tar.gz

安装

tar zxvf uwsgi-1.0.2.1.tar.gz
cd uwsgi-1.0.2.1/
python uwsgiconfig.py --build

配置

cp nginx/uwsgi_params /usr/local/nginx/conf/
vi /usr/local/nginx/conf/nginx.conf

编辑Nginx配置文件添加,uWSGI监听8000端口,这个原理跟PHP的fastcgi相同

    server {
        listen        80;
        server_name py.wuwangwo.net;

        location / {
            root  /data/htdocs/py.wuwangwo.net;
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:8000;
        }

        access_log  /data1/logs/py.wuwangwo.net.access.log;
    }

重新启动Nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -s reload

配置web站点

cd /data/htdocs/py.wuwangwo.net
vi uwsgi.xml

编辑uWSGI配置文件,他也同样支持.ini文件等的配置形式,个人习惯不同,具体可以参照官方示例:http://projects.unbit.it/uwsgi/wiki/Example


127.0.0.1:8000
myuwsgi

/data/htdocs/py.wuwangwo.net
2

编辑web.py文件

#!/usr/bin/env python

import os
import web

urls = ('/(.*)', 'hello')

app = web.application(urls, globals())

class hello:
    def GET(self, name):
        if not name:
            name = "World"
        return "Hello" + name + "!"

application = app.wsgifunc()

启动uWSGI,添加--daemonize参数以后台方式运行

/usr/local/uwsgi-1.0.2.1/uwsgi -x /data/htdocs/py.bukaopu.org/uwsgi.xml --daemonize /data/htdocs/py.wuwangwo.net/uwsgi.error.log

停止uWSGI

killall -9 uwsgi

简述uWSGI+Nginx+Python 搭建过程》有一个想法

发表回复