3.使用apache的服务
编辑apache的.htaccess文件来启用cgi
vim .htaccess
添加如下代码
Options +ExecCGI AddHandler cgi-script .py <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.cgi/$1 [L] </IfModule>
4.检查并发现错误
现在,你的web主目录应该是这个样子
$ ls -F ~/example.com fcgi.py index.cgi* web/
使用你的浏览器访问http://example.com/(您自己映射在dreamhost的域名),应该就可以看到问候语.如果浏览器显示"500内部错误",那就应该检查下错误日志.
tail -n 30 ~/logs/example.com/http/error.log (译者注:上面的内容足够成功运行web.py了,下面的内容我也还没有进行,所以仅供参考)
FCGI
- 使用FastCGI架设您的域名或二级域名.假设您的域名是todo.dabase.com
- cd; rmdir ~/todo.dabase.com
- svn co http://svn.natalian.org/projects/todo/
- ln -s ~/todo ~/todo.dabase.com
- Tweak ~/todo with your mysql db (see config.py) and email stuff for errors
并不建议您在shell下进行fcgi的测试开发,因为如果fastcgi的进程开始运行后,停止或重启这个进程都是一件让人头痛的事情.您可以使用web.reloader在本地进行开发,这样,您的任何改变将立即被反应到您的web程序.
Benchmarking
ab is from the apache2-utils Debian package. 从apache2-utils Debian包中找到ab组件
/usr/sbin/ab -c 4 -n 300 http://todo.dabase.com/
4 concurrent connections pushing out 300 requests. If you find it too slow, considering running lighttpd on a dedicated server. 4个并发连接将产生300个请求.如果你发现它运行太慢,请考虑在一台专用服务器上运行lighttpd.
重启FastCGI进程
为了使新的代码起作用,你需要重启fcgi进程. 如下代码将会起作用:
killall python2.4
改进稳定性和加快启动速度
- 使用http://svn.saddi.com/py-lib/trunk/fcgi.py来代替较新的flup
- 按照如下方法修改wsgi.py :
--- wsgi.py (revision 130) +++ wsgi.py (working copy) @@ -13,8 +13,8 @@ def runfcgi(func, addr=('localhost', 8000)): """Runs a WSGI function as a FastCGI server.""" - import flup.server.fcgi as flups - return flups.WSGIServer(func, multiplexed=True, bindAddress=addr).run() + import fcgi as flups + return flups.WSGIServer(func, multiplexed=False, bindAddress=addr).run()
经典论坛讨论: http://bbs.blueidea.com/thread-2807966-1-1.html
本文链接:http://www.blueidea.com/tech/program/2007/5069.asp
出处:蓝色理想
责任编辑:moby
上一页 web.py的说明一 下一页
◎进入论坛网络编程版块参加讨论
|