Flask+Nginx+uwsgi部署

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flask+Nginx+uwsgi部署相关的知识,希望对你有一定的参考价值。

  • python安装
  • nginx安装
    • yum install nginx
  • python 虚拟环境创建
    • python3 -m venv venv
    • pip3 install flask
  • Nginx全局配置文件
    • cd /etc/nginx
    • cp nginx.conf nginx.conf_bak
    • vi nginx.conf
      • user root;
      • gzip on;
      • 注释sever{}
    • cd /etc/nginx/conf.d
    • vi mysite.conf
      • server {
      • listen  80;
      • server_name     120.78.61.245;
      • charset utf-8;
      • access_log      /var/log/nginx/log/mysite.access.log    main;
      • error_log       /var/log/nginx/log/mysite.error.log     warn;
      • location / {
      • root    /var/www/mysite;
      • index   index.html index.htm;
      • include uwsgi_params;
      • uwsgi_pass      127.0.0.1:5000;
      • uwsgi_param     UWSGI_PYHOME    /var/www/venv;
      • uwsgi_param     UWSGI_CHDIR     /var/www/mysite;
      • uwsgi_param     PYTHONPATH      /var/www/mysite;
      • uwsgi_param     UWSGI_MODULE    run;
      • uwsgi_param     UWSGI_CALLABLE  app;
      • }
      • }
  • 安装uwsgi
    • pip3 install uwsgi
    • cd /var/www/mysite/
    • vi uwsgi.ini
      • [uwsgi]
      • socket = 127.0.0.1:5000 #注: 指定某个固定端口
      • processes = 4   #注:跑几个进程,这里用4个进程
      • threads = 2
      • master = true
      • pythonpath = /var/www/mysite
      • module = run
      • callable = app
      • memory-report = true
  • 启动nginx
    • cd /var/log/nginx
    • mkdir log
    • nginx -t -c /etc/nginx/nginx.conf
    • systemctl start nginx.service
      • 备注systemctl status nginx.service可以查看具体错误
  • 启动uwsgi(在venv下)
    • cd /var/www/
    • uwsgi --ini mysite/uwsgi.ini

以上是关于Flask+Nginx+uwsgi部署的主要内容,如果未能解决你的问题,请参考以下文章

Flask+uwsgi+nginx 部署

使用 Nginx + uWSGI 部署 Flask 应用

用uWSGI和Nginx部署Flask项目

Flask+uwsgi+Nginx+Ubuntu部署教程

Flask+uwsgi+Nginx+Ubuntu部署

Flask+uwsgi+Nginx+Ubuntu部署