功能介紹
FLUP是python下的一種WSCGI的實現,可以比較容易地與NGINX等HTTP Server進行搭配使用。
flup安裝
yum install python-flup
如果希望用spawn-fcgi來啓動wscgi程序,還可以安裝spawn-fcgi:
yum install spawn-fcgi
代碼範例
web.py代碼如下:
#!/usr/bin/env python #coding=utf-8 from flup.server.fcgi import WSGIServer def webapp(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) content = "Hello World!" return [content] if __name__ == '__main__': WSGIServer(webapp, multithreaded=True, multiprocess=False, bindAddress=('127.0.0.1', 8008)).run()
啓動flup
上面的代碼可以以standalone的模式啓動,如:
nohup python ./web.py &
也可以用spawn-fcgi啓動:
spawn-fcgi -f web.py -a 127.0.0.1 -p 8008 -u tinfo -F 5
ngnix配置
我們可以通過修改/etc/nginx/nginx.conf:
server { listen 80; server_name ***.***.com; location /index.cgi { fastcgi_pass 127.0.0.1:8008; include fastcgi.conf; } }