Windows下nginx配置python服务器

Windows下nginx配置python服务器

  • Windows下nginx配置python服务器
    • 安装python
    • 安装flup包
    • 创建Python server
    • 配置nginxconf
    • 启动nginx
    • 测试

参考文献 http://blog.163.com/sky20081816@126/blog/static/1647610232010824262695/

安装python

运行WinPython-64bit-2.7.9.2.exe
并手动设置PATH环境变量

安装flup包

下载 http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
解压
在解压目录中运行

python setup.py install

成功提示
Installed f:/python25/lib/site-packages/flup-1.0.2-py2.5.egg
Processing dependencies for flup==1.0.2
Finished processing dependencies for flup==1.0.2

创建Python server

创建fcgi.py文件

#!/usr/bin/python
# encoding : utf-8
from flup.server.fcgi import WSGIServer
def myapp(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World!\n']
if __name__  == '__main__':
   WSGIServer(myapp,bindAddress=('127.0.0.1',8008)).run()

在命令行中运行

python fcgi.py --method=prefork/threaded minspare=50 maxspare=50 maxchildren=1000

这个server即在8080端口监听http请求,若有请求则返回“hello world”

配置nginx.conf

http {
    server{
        listen  8000; #nginx服务端口
        server_name test.com; 
        location /{
            fastcgi_pass  127.0.0.1:8008;  #python server的端口
            fastcgi_param SCRIPT_FILENAME "";
            fastcgi_param PATH_INFO $fastcgi_script_name;
            include fastcgi.conf;
        }
    }
}

启动nginx

nginx.exe

测试

打开浏览器,输入localhost:8000
会看到hello world

你可能感兴趣的:(Windows下nginx配置python服务器)