webpy+nginx+uwsgi安装配置

时间:2014-05-28 03:04:41   收藏:0   阅读:281

转:(1)安装Nginx
1.1 下载nginx-1.0.5.tar.gz并解压
1.2 ./configure (也可以增加--prefix= path指定安装路径)
此时有可能会提示缺少pcre支持,如果要安装pcre的话可以通过 yum install pcre-devel 来实现安装
1.3 make
1.4 make install

(2)安装uWSGI
2.1 下载uwsgi-0.9.8.2.tar.gz并解压
2.2 make
在安装uWSGI的时候有可能提示说是libxml2不存在,针对此情况,建议通过 yum install libxml2-devel来解决

(3)安装web.py
可以通过easy_install web.py来安装最新版,不过我在安装0.36的时候出错,而且是语法错误,所以最终回退到0.35版

(4)以一个简单的webpy程序作为示例。以下代码是一个完整的webpy程序(webpytest.py)

bubuko.com,布布扣
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()
bubuko.com,布布扣

 

 

最后一句的application = app.wsgifunc()是关键,此时才可以通过wsgi进行访问

(5)启动uWSGI
uwsgi -s 127.0.0.1:9000 -w webpytest

(6)更改Nginx相关配置(nginx.conf)

bubuko.com,布布扣
server {
        listen       80;
        server_name  10.0.11.226;
  
        #charset koi8-r;
  
        #access_log  logs/host.access.log  main;
  
        location / {
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:9000;
            uwsgi_param UWSGI_CHDIR /usr/local/sphinx;
            uwsgi_param UWSGI_SCRIPT webpytest;
        }
bubuko.com,布布扣

 

 

注意:uwsgi_pass 的相关配置必须和启动uwsgi时的一致!UWSGI_CHDIR是指程序所在的目录,UWSGI_SCRIPT是指启动哪个程序(注意,这里必须去掉py后缀).测试发现,UWSGI_CHDIR 和UWSGI_SCRIPT也可以不要!

(6)启动nginx
/usr/local/nginx/sbin/nginx
重启nginx命令为(/usr/local/nginx/sbin/nginx -s stop)

(7)通过http即可访问
http://10.0.11.226

以上只是一个非常简单的搭建过程,仅作记录!

webpy+nginx+uwsgi安装配置,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!