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/
参考: