当前位置: 移动技术网 > 网络运营>服务器>Linux > ubuntu lighttpd+webpy (fastcgi)配置方法

ubuntu lighttpd+webpy (fastcgi)配置方法

2019年05月24日  | 移动技术网网络运营  | 我要评论
lighttpd 的配置脚本在 /etc/lighttpd/lighttpd.conf,采用默认值
缺省的server.document-root路径是 /var/www
具体实施步骤:
1) 首先实现一个 python 脚本
touch /var/www/hello.py
chmod 755 /var/www/hello.py
vim /var/www/hello.py
复制代码 代码如下:

#!/usr/bin/env python
import web
urls = (
'/hello', 'hello', '/hello/(.*)$', 'hello'
)
app = web.application(urls, globals())
class hello:
def get(self, name=none):
if not name:
name = 'world'
return 'hello, ' + name + '!'
if __name__ == "__main__":
app.run()

2) 配置 fastcgi
vim /etc/lighttpd/conf-available/10-fastcgi.conf
复制代码 代码如下:

server.modules += ( "mod_fastcgi" )
fastcgi.server = ("/hello" =>
((
"bin-path" => "/var/www/hello.py",
"socket" => "/tmp/hello.py.socket",
"max-procs" => 1,
"bin-environment" => (
"real_script_name" => ""
),
"check-local" => "disable"
))
)

3) 启用 fastcgi
lighttpd-enable-mod fastcgi
4) 重启 lighttpd
/etc/init.d/lighttpd force-reload
5) 在浏览器中验证结果
http://localhost/hello 得到的结果是 hello, world!
http://localhost/hello/sendltd 得到的结果是 hello, sendltd!
6) 补充说明
这样配置静态页面和动态页面可以共存,不需要配置 mod_rewrite。
每次修改 python 脚本都要重启lighttpd。
可以在 10-fastcgi.conf 中 配置多个sever,但是socket不能相同 。
[l参考链接]

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网