Nginx教程

Flask + uwsgi + nginx 2021

本文主要是介绍Flask + uwsgi + nginx 2021,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Flask线上环境部署

  • 结构
    Flask + uwsgi + nginx
  • uwsgi部署
    uwsgi最新稳定版(uwsgi-2.0.19.1)源码

    yum install gcc python3-devel.x86_64
    wget  http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
    tar xf uwsgi-latest.tar.gz
    cd uwsgi-2.0.19.1
    python3 uwsgiconfig.py --build
    python3 setup.py install

    注意:
    编译好会生成一个uwsgi可执行文件
    用什么编译环境就是什么,不支持uwsgi.ini自定义环境

  • uwsgi配置文件

    #vi uwsgi.ini 
    [uwsgi]
    socket = 127.0.0.1:8000
    chdir = /data/soft/agent_flask
    wsgi-file = /data/soft/agent_flask/myproject/wsgi.py
    callable = app
    master = true
    processes = 10
    buffer-size=65535
    vacuum = true
    enable-threads = true
    pidfile = /data/soft/agent_flask/logs/uwsgi.pid
  • nginx配置文件

    #vi agent_flask.conf 
    server
    {
        listen       80;
        server_name 127.0.0.1 192.168.209.211;
        charset utf-8;
        client_max_body_size 75M;
        index index.html index.htm index.php;
        location /
        {
                include uwsgi_params;
                uwsgi_pass 127.0.0.1:8000; # uwsgi启动端口
                uwsgi_param UWSGI_PYTHON /usr/bin; # 系统中Python的目录路径
                uwsgi_param UWSGI_SCRIPT uwsgi:app; #项目入口文件
        }
    
        access_log  /data/logs/agent_flask.acc.log main;
        error_log   /data/logs/agent_flask.err.log error;
    }
  • 启动

    ./uwsgi uwsgi.ini
  • 关闭
    ./uwsgi  --stop /data/soft/agent_flask/logs/uwsgi.pid

个人GitHub项目有纯净编译好的uwsgi环境

这篇关于Flask + uwsgi + nginx 2021的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!