学以致用

focus on Python , C++, and some interest in Go and R

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

废话少说,直接书写详细搭建过程,以作记录。

(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)

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()

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

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

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

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;
        } 

注意: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

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

posted on 2011-07-20 15:13  Jerry.Kwan  阅读(5615)  评论(2编辑  收藏  举报