天天看點

Python程式設計:uWSGI+nginx配置flask執行個體安裝子產品部署flasknginx配置

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應用快速入門

繼續閱讀