zoukankan      html  css  js  c++  java
  • nginx+python+fastcgi环境配置(flup版本)

    昨天花了一整天的时间研究搭建了nginx+python+fastcgi环境,并测试没问题,由于是第一次,并且参考了网上很多东西,网上也有很多,但还是把自己的过程记录下。

           主要感谢这位兄弟的文章给了我很大的帮忙http://blog.csdn.net/linvo/article/details/5870498,不过这位兄弟的测试代码我没跑成功。

            一、环境配置主要分以下几步

            1、Linux环境和python环境(此步骤省略)

            2、Nginx环境、flup、spawn-fcgi工具的部署如下

    [plain] view plain copy
     
    1. wget http://nginx.org/download/nginx-1.2.1.tar.gz  
    2. tar -xzvf nginx-1.2.1.tar.gz  
    3. cd nginx-1.2.1  
    4. ./configure --prefix=/usr/local/nginx-1.2.1 --with-http_stub_status_module --with-http_ssl_module --with-cc-opt='-O2'  
    5. make  
    6. make install  
    7.   
    8. wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz  
    9. tar -xzvf flup-1.0.2.tar.gz  
    10. cd flup-1.0.2  
    11. python setup.py install  
    12.   
    13. http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz  
    14. tar -xzvf spawn-fcgi-1.6.3.tar.gz  
    15. cd spawn-fcgi-1.6.3  
    16. ./configure  
    17. make  
    18. make install  
    19. 默认位置在/usr/local/bin/spawn-fcgi  

           二、配置nginx.conf支持fastcgi

            具体配置不详说,下面是配置的一个虚拟主机。/naiveloafer.cgi就是配置的fastcgi,请求会转发到5678端口的程序,配置好后重启nginx服务。

    [plain] view plain copy
     
    1. server {  
    2.         listen      83;  
    3.         server_name naiveloafer.xxx.com;  
    4.         access_log  logs/naiveloafer.xxx.com main;  
    5.         location / {  
    6.             root /usr/local/nlweb/htdocs;  
    7.             index index.html index.htm;  
    8.         }  
    9.         location /naiveloafer.cgi {  
    10.             fastcgi_pass 127.0.0.1:5678;  
    11.             include fastcgi.conf;  
    12.         }  
    13.     }  

    编写fcgi脚本,并保存为fcgi.py:

    [python] view plain copy
     
    1. #!/usr/bin/env python  
    2. #coding=utf-8  
    3. #author:naiveloafer  
    4. #date:2012-06-07  
    5.   
    6. from flup.server.fcgi import WSGIServer  
    7.   
    8. def naiveloafer_app(environ, start_response):  
    9.     start_response('200 OK', [('Content-Type', 'text/plain')])  
    10.     content = "Hello World!naiveloafer"  
    11.     return [content]  
    12.   
    13. if __name__  == '__main__':  
    14.    WSGIServer(naiveloafer_app).run()  

    开启监听,具体参数见那位兄弟的文章

    [plain] view plain copy
     
    1. spawn-fcgi -f /usr/local/nlweb/cgi-bin/fcgi.py -a 127.0.0.1 -p 5678 -u nobody -F 5  

    至此,通过web或者HTTP请求就能从fastcgi返回信息了。但这只是一个具体的配置

    具体如何处理请求的参数,获取请求的数据看

  • 相关阅读:
    BZOJ 3196 二逼平衡树
    BZOJ 4241 历史研究
    Problem 71:Ordered fractions
    矿工安全生产
    Codeforces 771C:Bear and Tree Jumps
    Problem 77:Prime summations
    Problem 69:Totient maximum
    关于Euclid算法
    团体程序设计天梯赛-练习集
    埃蒙的时空航道
  • 原文地址:https://www.cnblogs.com/xiaoleiel/p/8301429.html
Copyright © 2011-2022 走看看