您当前的位置: 首页 >  彭世瑜 Python

Python编程:uWSGI+nginx配置flask实例

彭世瑜 发布时间:2018-09-10 19:50:20 ,浏览量:3

uWSGI简单理解为:Web服务器

安装模块
pip install uwsgi
pip install uwsgitop # 监控模块

uWSGI测试

# foobar.py

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"]
$ uwsgi --http :9090 --wsgi-file foobar.py
部署flask
# myflaskapp.py

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "Hello world!"
# yourfile.ini

[uwsgi]
socket = 127.0.0.1:3031
venv = /Users/qmp/.virtualenvs/py3   # python环境路径
chdir = /Users/workspace/mydemo/uwsgi_demo
wsgi-file =  myflaskapp.py
callable = app
processes = 4
threads = 2
stats = 127.0.0.1:9191
nginx配置
server {
    listen  9090;

    server_name localhost;

    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:3031;
    }

}

通过nginx将9090端口的内容转发到uwsgi的3031端口

运行

$ uwsgi yourfile.ini

访问测试: nignx端口:http://127.0.0.1:9090/

参考: Python/WSGI应用快速入门

关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 3浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0496s