nginx+python+fastcgi环境搭建

安装flup python模块
wget https://pypi.python.org/packages/source/f/flup/flup-1.0.tar.gz#md5=530801fe835fd9a680457e443eb95578 --no-check-certificate
    tar -xzvf flup-1.0.tar.gz
    cd flup-1.0
    python setup.py install 等待安装完成


nginx配置

在/usr/local/nginx/conf/nginx.conf文件中添加如下:

location = / {
        fastcgi_pass 127.0.0.1:8088;
        fastcgi_param SCRIPT_FILENAME fcgi$fastcgi_script_name;
        include fastcgi.conf;
        }

重启nginx

测试代码:文件名:main.py

   import sys
import traceback
import Ice
import json
from flup.server.fcgi import WSGIServer


#Http请求处理和回复
def HttpReqHandler(environ, start_response):
try:
status = '200 OK'

response_headers = [('Content-Type', 'text/json')]
start_response(status, response_headers)


return ["hello world"]


if __name__  == '__main__':
WSGIServer(HttpReqHandler, bindAddress=('127.0.0.1',8088)).run()


启动pythonfcgi模块

python main.py --method=prefork/threaded minspare=10 maxspare=20 maxchildren=50


浏览器请求URL:http://192.168.100.195:8080

可看到打印:hello world


你可能感兴趣的:(Python)