nginx + uWSGI +flask应用部署

xiaoxiao2021-02-28  95

简单写一下过程 操作系统版本:Ubuntu 16.4 主要参考资料: http://uwsgi-docs-zh.readthedocs.io/zh_CN/latest/WSGIquickstart.html 按照上面网址来做就好了 (1)安装软件 apt-get安装nginx,这种方式安装的版本较低nginx version: nginx/1.10.0 (Ubuntu)

sudo apt-get install nginx

apt-get安装pip

sudo apt-get install python-pip

pip 安装 uwsgi ,flask

pip install uwsgi pip install flask

uWSGI 2.0.15 版本不同,指令的参数会不同

(2)配置文件 打开ngnix配置文件

sudo vi /etc/nginx/sites-enabled/default

将原来的location修改为

location / { include uwsgi_params; uwsgi_pass 127.0.0.1:3031; } 这表示“传递每一个请求给绑定到3031端口并使用uwsgi协议的服务器”。 之后记得重启服务器。

配置文件出错,可以通过下面检查

sudo nginx -t

(3)验证 准备一个简单的flask应用,如

from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "<span style='color:red'>I am app 1</span>"

使用指令

uwsgi --socket 127.0.0.1:3031 --wsgi-file myflaskapp.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191

结果截图:

出现的主要问题: (1)uwsgi版本不对,导致指令不能用,推荐用pip安装,不要用apt-get (2)不知道sudo nginx -t可以定位配置文件的错误,浪费了时间

转载请注明原文地址: https://www.6miu.com/read-41708.html

最新回复(0)