Pylons 入门实例教程 – 发布应用

前面几篇教程简单讲述了如何使用 Pylons 进行 WEB 方面开发的步骤,包括简单的 Hello、表单和数据库操作等内容。本篇将描述一下如何在正式环境中发布基于 Pylons 的 WEB 应用。

测试环境:Nginx 0.8.53 + FastCGI 模式 (需要安装 flup 模块)

pip install flup
# easy_install -U flup

测试代码,延用前面的 Hello 示例。

mac:python smallfish$ paster create -t pylons hello
mac:python smallfish$ cd hello/
mac:hello smallfish$ paster controller hi
mac:hello smallfish$ paster serve --reload development.ini

确保以上过程无错,访问:http://127.0.0.1:5000 可以看到默认页面。

好把,开始配置发布环境。
需要修改 development.ini 配置文件,找到 [server:main] 节点,修改其中的 use 方式(默认是 egg:Paste#http)。

[server:main]
use = egg:PasteScript#flup_fcgi_thread
host = 0.0.0.0
port = 5000

另外建议修改 [DEFAULT] 节点中 debug = false,以免错误会打印具体的环境和堆栈信息。

到这里 Pylons 部分以及设置好了,如果出现一下错误:

LookupError: Entry point 'flup_fcgi_thread' not found in egg 'Paste'

请注意上面的 use 部分里是 PasteScript 而不是 Paste哦。淡定淡定,别光看后面的 http 改成 flup_fcgi_thread。

下面修改 Nginx 的配置 nginx.conf,修改其中 / 部分设置。

        location / {
            fastcgi_pass   127.0.0.1:5000;
            fastcgi_index  index;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_intercept_errors off;
        }

其中 fastcgi_pass 中 host 和 port 对应 development.ini 中的配置。

好把,这里可以启动,看看是否正确,请注意相应的目录。

启动 Pylons 部分(启动 daemon 进程,或参考搜狐邮箱使用的 zdaemon 来管理进程):

mac:hello smallfish$ paster serve --reload development.ini  --daemon start
# 注意,正式环境中请去除 reload 参数
# daemon 后面参数有 start | stop | restart | status,可以很方便的管理进程

启动 Nginx 部分:

mac:~ smallfish$ sudo /opt/nginx/sbin/nginx

尝试一下访问: http://localhost/ 和 http://localhost/hi/index 。是不是都可以了?OK,到这里已经整合好了。

这里是采用 FastCGI 方式发布,当然还可以用默认 http 或者本地 socket 方式,然后通过 proxy_pass 方式转发过去也是可以的。

当然,这个只是简单示例,可能正式发布时候需要注意的事项比这个复杂的多。这里只是介绍一种方式而已。

希望通过这一系列的教程,希望能对喜欢 Python 和关注 Pylons 框架的朋友能有所帮助。

前几篇链接分别如下:

1. Pylons 入门实例教程 – Hello
2. Pylons 入门实例教程 – 表单和文件上传
3. Pylons 入门实例教程 – 数据库操作
4. Pylons 入门实例教程 – cookie 和 session

 

http://chenxiaoyu.org/blog/archives/351

Using HTTPLoris is simple. In its most basic form, HTTPLoris merely needs a copy of Python 2.6. On a Linux machine, one must simply invoke the script in a terminal, stating a site to test: motoma@rocksalt:/home/motoma$ python pyloris-3.0.py motomastyle.com On Mac OS X, one invokes PyLoris the same way. Using the Terminal Application: hotdog:/Users/Motoma/ motoma$ python pyloris-3.0.py motomastyle.com Using HTTPLoris in Windows is a little different. One will need to know the location of the Python installation, and be in the proper directory. Load up a command prompt: C:\Users\Motoma\Desktop\pyloris-3.0>C:\Python26\python.exe pyloris-3.0.py motomastyle.com Advanced Options Invoking HTTPLoris by using the commands above start a limited to 500 connections across 50 threads, each sending at 1 byte/second and waiting until the connection is forced shut by the server. While this behavior will bog down an Apache server with the default settings, it is not a very thorough test. The following are some additionall options that will allow one to customize the way HTTPLoris works: -a, --attacklimit The --attacklimit flag restricts the number of total connections (current + completed) during a single session. Set this to zero to specify no limit. -c, --connectionlimit Adjusting the --connectionlimit flag can drastically change how well HTTPLoris performs. The --connectionlimit flag directly controls the number of concurrent connections held during the session. In a base Apache environment, when this number is above the MaxClients setting, the server is unresponsive. -t, --threadlimit This is the number of attacker threads run during the session. -b, --connectionspeed This is the connection speed for each individual connection in bytes/second. Comparing this with the lenght of the request, and you should have an accurate guess of how long each connection should linger. -f, --finish Specifying the --finish flag will cause HTTPLoris to finish and close connections upon
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值