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文件,我用最简单的配置:
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<