昨天没有把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!
安装成功