据说是官方推荐的部署方式。通过Lighttpd的Fastcgi来部署。
适合部署些小应用。

1 安装环境

#安装Lighttpd
apt-get install lighttpd
#安装Webpy及其依赖
pip install web.py flup

2 配置Fastcgi

通过apt方式安装的,配置在/etc/lighttpd目录下

#lighttpd.conf
#添加模块
    "mod_rewrite"
    "mod_fastcgi"
#在static-file.exclude-extensions中添加
    ".py"
#在include_shell前添加配置
    fastcgi.server = ( ".py" =>
        (( "socket" => "/tmp/fastcgi.socket", #fastcgi名
            "bin-path" => "/var/www/html/index.py", #应用入口文件
            "max-procs" => 3, #子进程个数
            "bin-environment" => (
                "REAL_SCRIPT_NAME" => ""
            ),
            "check-local" => "disable"
        )))
#转发配置
    url.rewrite-once = (
        "^/favicon.ico$" => "/static/favicon.ico",
        "^/static/(.*)$" => "/static/$1",
        "^/(.*)$" => "/index.py/$1",
    )

3 重启&测试

重启:

service lighttpd restart

测试用例(index.py):

#coding=utf-8
import web
urls = (
    "/(.*)", "index",
)
app = web.application(urls, globals())
class index:
    def GET(self, name):
        web.header('Content-Type','text/html; charset=UTF-8')
        return "Hello " + name
if __name__ == "__main__":
    app.run()

现在可以访问不同的路径康康效果:

http://localhost/
http://localhost/test

文章版权:远望江来 - 人的一生当然要靠自我奋斗,当然也要考虑历史的行程

本文链接:https://blog.chutian.bid/archives/70.html

转载请注明文章原始出处 !

添加新评论

返回顶部
Typecho 强力驱动. © Powered by Zhangtinghui. Theme by Postbird.