使用Lighttpd部署Webpy应用
据说是官方推荐的部署方式。通过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