nginx配置python的cgi
2016-03-29 16:03
543 查看
nginx不支持cgi,也就是nginx 不能直接执行外部脚本。但是nginx支持fastcgi。所以为了在nginx运行fastcgi,我们采用flup,flup是fastcgi的一种实现。这里是官网https://www.saddi.com/software/flup/ 我用最简单的模式就是 nginx+flup。
* 第一步安装flup。当前目录转为\python安装目录\Lib\site-packages 但后用easy_install安装flup的egg文件。
* 第二步就是配置nginx.conf文件,我用最简单的配置:
* 第三步也是最蛋疼的一部就是测试代码。用的pytho你上的示例代码:
import sys, os
from flup.server.fcgi import WSGIServer
def app(environ, start_response):
start_response(‘200 OK’, [(‘Content-Type’, ‘text/html’)])
结果一直提示错误:
网上也有说要修改fcgi_base.py的,我觉得不对,于是找到有人在最后一行代码中指定地址和端口。之前也一直在像端口在哪里设置。修改之后正常运行,至少能监听我要的端口。
最后一行修改为:
估计这就是最简单的python+fcgi模式。Django之类的估计是在flup上的加强版本。不懂。
* 第一步安装flup。当前目录转为\python安装目录\Lib\site-packages 但后用easy_install安装flup的egg文件。
* 第二步就是配置nginx.conf文件,我用最简单的配置:
location ~ ^/test { include fastcgi_params; fastcgi_pass 127.0.0.1:10080; }
* 第三步也是最蛋疼的一部就是测试代码。用的pytho你上的示例代码:
from cgi import escape
import sys, os
from flup.server.fcgi import WSGIServer
def app(environ, start_response):
start_response(‘200 OK’, [(‘Content-Type’, ‘text/html’)])
yield '<h1>FastCGI Environment</h1>' yield '<table>' for k, v in sorted(environ.items()): yield '<tr><th>%s</th><td>%s</td></tr>' % (escape(k), escape(v)) yield '</table>' WSGIServer(app).run()
结果一直提示错误:
sock = socket.fromfd(FCGI_LISTENSOCK_FILENO, socket.AF_INET, AttributeError: 'module' object has no attribute 'fromfd'
网上也有说要修改fcgi_base.py的,我觉得不对,于是找到有人在最后一行代码中指定地址和端口。之前也一直在像端口在哪里设置。修改之后正常运行,至少能监听我要的端口。
最后一行修改为:
WSGIServer(app, bindAddress=('127.0.0.1',10080)).run()
估计这就是最简单的python+fcgi模式。Django之类的估计是在flup上的加强版本。不懂。
相关文章推荐
- Nginx-虚拟主机
- Nginx日志按天分割
- Nginx的事件处理机制
- zf2框架的PHP程序,测试环境使用apache,准生产环境使用nginx,出现的问题
- nginx日志统计分析
- 如何使Nginx支持FastCGI(C/C++) (支持调用多个FastCGI程序)
- CentOS+nginx+uwsgi+Python 多站点环境搭建
- centos6.5下安装nginx
- 五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(下)
- 五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(上)
- Nginx配置文件
- Nginx 配置从零开始
- mac 安装 nginx 环境
- nginx日志切割
- nginx
- nginx rewrite规则大杂烩
- 查看apache,mysql,nginx,php的编译参数
- 你知道Nginx的七大优势吗?
- Nginx 配置实践
- 源码编译安装nginx1.4.7