您的位置:首页 > 理论基础 > 计算机网络

lighttpd支持python

2015-11-18 22:49 531 查看

lighttpd使用fastcgi同时支持php和python

发表回复

我们前面已经谈到 用lighttpd的scgi模块部署webpy, 类似于nginx, ligthttpd同样可以使用fasctcgi同时支持php和python

在 /etc/lighttpd/lighttpd.conf 注释掉

#server.document-root = “/var/www”

#server.errorlog = “/var/log/lighttpd/error.log”

#server.username = “www-data”

#server.groupname = “www-dat

在/etc/lighttpd/conf-enabled 创建文件,或者符号链接 mobile.conf (注意要以 .conf结尾),内容如下

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

server.document-root     = "/home/carbon/stealth"
server.errorlog                = "/home/carbon/lighty/log/error.log"
accesslog.filename         = "/home/carbon/lighty/log/access.log"

server.username             = "carbon"
server.groupname           = "carbon"

fastcgi.server = (
".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/home/carbon/lighty/fastcgi.php.socket",
"max-procs" => 1,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
)),

"" => ((
"socket"    => "/home/carbon/lighty/fastcgi.python.socket",
"bin-path"  => "/home/carbon/stealth/t.py",
"max-procs" => 1,
"bin-environment" => (
"REAL_SCRIPT_NAME" => ""
),
"check-local" => "disable"
)),
)

重启后lithttpd

在/home/carbon/stealth编辑如下文件 i.php

和 t.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import web

web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)

urls = ( '/hello', 'hello')
class hello:
def GET(self):
web.header("Content-Type","text/html; charset=utf-8")
return "Hello world!"

app = web.application(urls, globals())
if __name__ == "__main__":
app.run()

用浏览器访问
http://localhost/i.php

http://localhost/hello
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: