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]
# 根據(jù)flask程序的文件名
module = hello:app
master = true
# 后臺進程數(shù)
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:文章來源:http://www.zghlxwxcb.cn/news/detail-607709.html
/usr/lib/python37/bin/uwsgi --ini uwsgi.ini
6. 啟動nginx:文章來源地址http://www.zghlxwxcb.cn/news/detail-607709.html
nginx # 啟動Nginx服務(wù)
nginx -s stop # 停止Nginx服務(wù)
ps -aux | grep nginx # 查看Nginx的運行狀態(tài)
到了這里,關(guān)于flask、uwsgi、nginx 部署的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!