1)安装lighttpd:
wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.30.tar.gz
./configure -prefix /opt/modules/lighttpd
make
make install
cp doc/initscripts/rc.lighttpd.redhat /etc/init.d/lighttpd
修改启动脚本:将第29行修改为:
lighttpd="/opt/modules/lighttpd/sbin/lighttpd"
chmod a+rx /etc/init.d/lighttpd
cp -R doc/config/conf.d /etc/lighttpd/
cp -R doc/config/vhosts.d/ /etc/lighttpd/
cp doc/config/*.conf /etc/lighttpd/
修改lighttpd配置文件:vi /etc/lighttpd/lighttpd.conf
var.basedir = "/var/www/localhost"
var.logdir = "/var/log/"
#载入一些要用到的模块
server.modules = (
"mod_access",
"mod_fastcgi",
"mod_rewrite",
"mod_accesslog",
)
server.document-root = "/opt/test"
server.pid-file = "/opt/test/lighttpd.pid"
server.errorlog = var.logdir + "/lighttpd-error.log"
server.port = 9001
accesslog.filename = var.logdir + "/lighttpd-access.log"
#fastcgi模块设置
Fastcgi.server = ( "/test.py" =>
( (
"socket"=>"/tmp/fastcgi-wen.socket",
"bin-path"=>"/opt/test/testpy",
"max-procs"=>2, #python子进程个数
"check-local"=>"disable", )))
#rewrite模块设置
url.rewrite-once = (
"^/(.*)$" => "/test.py/$1", #把所有请求重定向到hello.py
)
2)安装web.py
easy_install web.py
如果easy_install安装失败,也可以下载源代码包进行安装:
Python setup.py install
3)Hello world测试:
#!/usr/bin/env python
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, name):
if not name:
name = 'World'
return 'Hello, ' + name + '!'
if __name__ == "__main__":
app.run()
运行:python test.py
输出:http://0.0.0.0:8080/
打开其他窗口访问:curl http://0.0.0.0:8080/
如成功,则返回:hello world
修改脚本权限为:755
4)启动lighttpd:/etc/init.d/lighttpd restart
查看错误日志,确保启动成功
5)curl http://0.0.0.0:9001/