OS X下的lighttpd fastcgi python

昨天没有把Apaache2的fcgid搞定,今天试了试lighttpd + fastcgi +python
参考了蛮多的教程,小小总结一下

1.安装lighttpd 网上很多教程,不重复了
2.修改lighttpd.conf,主要改下面的

fastcgi.server = ( ".py" =>
(( "socket" => "/tmp/fastcgi.socket",
"bin-path" => "/Applications/xampp/xamppfiles/fcgi-bin/index.py",
"max-procs" => 10,
"bin-environment" => (
"index.py" => ""
)
))
)
url.rewrite-once = (
"^/favicon.ico$" => "/static/favicon.ico",
"^/static/(.*)$" => "/static/$1",
"^/media/(.*)$" => "/media/$1",
"^/(.*)$" => "/index.py/$1"
)

3.安装python flup
easy_install flup就OK了
4.创建 /Applications/xampp/xamppfiles/fcgi-bin/index.py

#!/usr/bin/env python2.5
try:
from flup.server.fcgi import WSGIServer

def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello World!\n']

WSGIServer(myapp).run()

except Exception, e:
print 'Content-Type: text/plain\r\n\r\n',
print 'Oops...'
print
print 'Trac detected an internal error:'
print
print e
print

5.参考robin的教程写一个启动的脚本

#!/bin/sh

case "$1" in
start)
/usr/local/lighttpd/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
;;
stop)
killall lighttpd
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: lighttpd.sh {start|stop|restart}"
;;
esac

exit 0

6.chmod +x lighttpd.sh
7.运行 lighttpd.sh start
8.访问 http://localhost/index.py
显示 Hello World!
安装成功
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值