>记录生活, 工作的点点滴滴...

Windows+nginx+flup6+webpy服务

环境: windows7 64位, python3.4, nginx1.11.10

1.python3安装, 环境变量设置

2.安装支持python3的flup
pip install flup6

3.ngnix 主要配置

#此段配置静态文件如js,css等, 如无此段配置, 会将本地相关文件请求按web.py的urls格式进行解析,无法返回
location /static/ {
        root D:/Software/web; # nginx+webpy application placed here.
        if (-f $request_filename) {
           rewrite ^/static/(.*)$  /static/$1 break;
        }
}
location / {
root D:\Software\web/test.py; #此为test.py的目录

fastcgi_pass 127.0.0.1:8000;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}

4. test.py文件

#!/usr/bin/env python 
#coding=UTF-8 
import web 
urls = ( '/(.*)', 'hello' ) 
app = web.application(urls, globals()) 
class hello: 
    def GET(self, name):
        if not name: name = 'World' 
            return 'Hello, ' + name + '!' 
if __name__ == "__main__":
    app.run()

5. 启动服务
双击启动nginx服务
cmd下运行: python test.py 8000 fastcgi
此处port:8000 为nginx中与fastcgi通信端口


发表于:2018-01-20 11:55:54浏览(365) 评论(0) Web