Lighttpd通过FastCGI运行web.py程序

web.py是个很小的python框架,特点就是小,连session都没有实现人家就发布了。前几天KungfuRails大会上他们吹牛说Sinatra可以写出世界上最小的Webapp,但是有web.py的化,那个最小至少要加上个“之一”。

Web.py在Lighttpd上通过fastcgi运行的配置,可以在web.py的网站上找到文档:
http://webpy.org/cookbook/fastcgi-lighttpd

实际我用的时候把静态的index.html用作首页,稍改动一下:

server.document-root = "/home/sun/projects/sdostatweb"

server.modules   += ( "mod_fastcgi" )
server.modules   += ( "mod_rewrite" )

server.port = 4000

mimetype.assign = (
    ".html" => "text/html"
)

index-file.names = ( "index.html" )

fastcgi.server = ( "/sdostatweb.py" =>
(( "socket" => "/tmp/fastcgi.socket",
        "bin-path" => "/home/sun/projects/sdostatweb/sdostatweb.py",
        "max-procs" => 5,
        "bin-environment" => (
        "REAL_SCRIPT_NAME" => ""
    ),
        "check-local" => "disable"
    ))
)

url.rewrite-once = (
    "^/$" => "/static/index.html",
    "^/flotr/(.*)$" => "/static/flotr/$1",
    "^/static/(.*)$" => "/static/$1",
    "^/(.*)$" => "/sdostatweb.py/$1",

)

另外用fastcgi的方式使用web.py,需要安装flup。

详细的事,可以看看新浪的Tim Yang的优化:
http://timyang.net/python/python-webpy-lighttpd/

我之前真不敢相信搜狐Mail是跑在web.py上。