zoukankan      html  css  js  c++  java
  • centos部署flask

    1.先安装uwsgi pip install uwsgi

    2.在你的项目根目录下创建一个配置文件uwsgiconfig.ini(uwsgi支持多种配置文件格式,xml,ini,json等)

    [uwsgi]socket = 127.0.0.1:8001 //启动程序时所使用的地址和端口,通常在本地运行flask项目,

    //地址和端口是127.0.0.1:5000,
    //不过在服务器上是通过uwsgi设置端口,通过uwsgi来启动项目,
    //也就是说启动了uwsgi,也就启动了项目。
    chdir = /home/www/ //项目目录

    wsgi-file = manage.py //flask程序的启动文件,通常在本地是通过运行
    // python manage.py runserver 来启动项目的

    callable = app //程序内启用的application变量名

    processes = 4 //处理器个数

    threads = 2 //线程个数

    stats = 127.0.0.1:9191 //获取uwsgi统计信息的服务地址

    3.保存配置文件,我们可以通过键入 uwsgi uwsgiconfig.ini 来启动uwsgi

    4.安装nginx

    5.修改nginx配置好文件

    events {
    worker_connections 1024;
    }
    http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;

    server {
    listen 80; //默认的web访问端口
    server_name xxx.xxx.xxx.xxx; //你的公网ip
    #charset koi8-r;
    access_log /home/www/WebBlogold/logs/access.log; //服务器接收的请求日志,
    //需要在项目文件夹下创建
    //logs文件夹,下同。
    error_log /home/www/WebBlogold/logs/error.log; //错误日志

    location / {

    include uwsgi_params; //这里是导入的uwsgi配置

    uwsgi_pass 127.0.0.1:8001; //需要和uwsgi的配置文件里socket项的地址
    //相同,否则无法让uwsgi接收到请求。

    uwsgi_param UWSGI_PYHOME /home/www/WebBlogold/venv; //python的位置(虚拟环境下)

    uwsgi_param UWSGI_CHDIR /home/www/WebBlogold; //项目根目录

    uwsgi_param UWSGI_SCRIPT manage:app; //启动项目的主程序(在本地上运行
    //这个主程序可以在flask内置的
    //服务器上访问你的项目)

    }
    }
    }
    下面是一堆#,全都是注释,不用管它。

    6.启动nginx,uwsgi即可

     

  • 相关阅读:
    SLAM+语音机器人DIY系列:(二)ROS入门——3.在ubuntu16.04中安装ROS kinetic
    SLAM+语音机器人DIY系列:(二)ROS入门——2.ROS系统整体架构
    2017年 年计划
    125. Valid Palindrome
    一道多树递归面试题
    顺序表查找和有序表查找
    c++中常见概念、关键字等的区别
    两个栈实现一个队列,两个队列实现一个栈
    150. Evaluate Reverse Polish Notation
    堆排序
  • 原文地址:https://www.cnblogs.com/wuhua1/p/8227805.html
Copyright © 2011-2022 走看看