1. 安装:
yum install openssl-devel nginx -y
pip3 install flask uwsgi
2. 基于flask编写例子hello.py,然后保存在/opt/txt/目录下:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World'
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8000, threaded=True)
3. 编写uwsgi的配置文件uwsgi.ini,如下所示:
[uwsgi]
# 根据flask程序的文件名
module = hello:app
master = true
# 后台进程数
processes = 4
# flask程序的路径
chdir = /opt/txt
socket = /opt/txt/uwsgi.sock
chmod-socket = 660
vacuum = true
http = 0.0.0.0:8000
buffer-size = 65536
pidfile = /opt/txt/uwsgi.pid
4. 修改nginx配置文件,在/etc/nginx/nginx.conf
注释掉/etc/nginx/nginx.conf的第一行——user nginx;并换成user root;
#user nginx; # 注释掉此行
user root; # 换成此行
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
修改nginx.conf配置文件中的server项:
server{
listen 80;
listen [::]80;
server_name _;
location / {
include uwsgi_params;
uwsgi_connect_timeout 30;
uwsgi_pass unix:/opt/txt/uwsgi.sock;
}
}
5. 启动uwsgi:文章来源:https://www.toymoban.com/news/detail-607709.html
/usr/lib/python37/bin/uwsgi --ini uwsgi.ini
6. 启动nginx:文章来源地址https://www.toymoban.com/news/detail-607709.html
nginx # 启动Nginx服务
nginx -s stop # 停止Nginx服务
ps -aux | grep nginx # 查看Nginx的运行状态
到了这里,关于flask、uwsgi、nginx 部署的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!