zoukankan      html  css  js  c++  java
  • Flask部署

    Flask部署

     

    安装必备环境

    配置

     

     

    安装必备环境

    nginx,uwsgi

     

     

    配置

     

    uwsgi

    启动配置文件

    # 配置 /home/liuwei/mycode/py/FlaskDemo/uwsgi.ini
    
    [uwsgi]
    #application's base folder,配置为项目的根目录
    base = /home/liuwei/mycode/py/FlaskDemo
    
    #python module to import
    # 这个app的值指的就是flask应用下的app.py
    app = app
    module = %(app)
    
    # 项目依赖的环境目录
    home = /home/liuwei/mycode/py/envs/flaskdemoenv
    pythonpath = %(base)
    
    #socket file's location,生成nginx依赖的文件,其中%n表示当前文件的名字
    socket = %(base)/%n.sock
    
    #permissions for the socket file
    chmod-socket = 666
    
    #the variable that holds a flask application inside the module imported at line #6
    callable = app
    
    #location of log files
    logto = /var/log/uwsgi/%n.log

    日志输出文件

    # 创建上面配置logto的文件夹,以及降权限
    sudo mkdir -p /var/log/uwsgi
    sudo chown -R liuwei:liuwei /var/log/uwsgi

    启动

    # cd  /home/liuwei/mycode/py/FlaskDemo
    uwsgi --ini uwsgi.ini
    
    # 当启动后,就会在项目目录下生成uwsgi.sock文件,这个文件被nginx依赖,所以你要先启动uwsgi
    
    #日志需要注意参数:
        # current working directory
        # detected binary path
        # uwsgi socket 0 bound to UNIX address
      # PythonHome、Python Version
      # 是否有报错信息
    
      
    
    # 查看启动成功的日志:
        *** Starting uWSGI 2.0.18 (64bit) on [Tue Dec 10 17:12:46 2019] ***
    compiled with version: 7.4.0 on 07 December 2019 04:39:53
    os: Linux-5.0.0-37-generic #40~18.04.1-Ubuntu SMP Thu Nov 14 12:06:39 UTC 2019
    nodename: liuwei-ThinkPad-E450
    machine: x86_64
    clock source: unix
    detected number of CPU cores: 4
    current working directory: /home/liuwei/mycode/py/FlaskDemo
    detected binary path: /home/liuwei/mycode/py/envs/flaskdemoenv/bin/uwsgi
    !!! no internal routing support, rebuild with pcre support !!!
    *** WARNING: you are running uWSGI without its master process manager ***
    your processes number limit is 31398
    your memory page size is 4096 bytes
    detected max file descriptor number: 1048576
    lock engine: pthread robust mutexes
    thunder lock: disabled (you can enable it with --thunder-lock)
    uwsgi socket 0 bound to UNIX address /home/liuwei/mycode/py/FlaskDemo/uwsgi.sock fd 3
    Python version: 3.6.9 (default, Nov  7 2019, 10:44:02)  [GCC 8.3.0]
    Set PythonHome to /home/liuwei/mycode/py/envs/flaskdemoenv
    *** Python threads support is disabled. You can enable it with --enable-threads ***
    Python main interpreter initialized at 0x565080299420
    your server socket listen backlog is limited to 100 connections
    your mercy for graceful operations on workers is 60 seconds
    mapped 72904 bytes (71 KB) for 1 cores
    *** Operational MODE: single process ***
    added /home/liuwei/mycode/py/FlaskDemo/ to pythonpath.
    WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x565080299420 pid: 31106 (default app)
    *** uWSGI is running in multiple interpreter mode ***
    spawned uWSGI worker 1 (and the only) (pid: 31106, cores: 1)

    nginx

    启动配置文件

    user root;
    worker_processes auto;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    # /×××/ngin  -c  /×××/nginx.conf   -s   stop
    pid /usr/local/nginx/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    http {
    
        include /usr/local/nginx/mime.types;
        default_type application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
    
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
      
    
        gzip on;
        gzip_disable "msie6";
    
        server {
            listen 80 default_server;
            #listen [::]:80 default_server;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            root /home/liuwei/mycode/py/FlaskDemo;
    
            server_name _;
    
    
            location /static {
                alias /home/liuwei/mycode/py/FlaskDemo/static;
            }
    
           location / {
                try_files $uri @yourapplication;
            }
            
             location @yourapplication {
                include /usr/local/nginx/uwsgi_params;
                # 这是和django有差别的地方
                uwsgi_pass unix:/home/liuwei/mycode/py/FlaskDemo/uwsgi.sock;
            }
    
        }
    }

    日志输出文件

    # 创建上面配置logto的文件夹,以及降权限
    sudo mkdir -p /var/log/nginx
    sudo chown -R liuwei:liuwei /var/log/nginx
    # 启动
    /***/nginx -t -c /***/nginx.conf
    
    /***/nginx -c /***/nginx.conf
    
    /***/nginx -c /***/nginx.conf -s stop

     

    前进时,请别遗忘了身后的脚印。
  • 相关阅读:
    01 Jq 基础
    01 属性
    input 编辑框 光标 的相关问题
    登录页面 文字 2 3 4 个字 等宽俩端对齐 空格
    复选框单选框与文字对齐问题的研究与解决
    在Python中对MySQL中的数据进行可视化
    输入2个坐标的数值求出对应坐标间的距离和圆的面积
    numpy中arange函数内起始值必须大于结束值,否则生成为空的一维数组
    条件语句练习-比分预测
    三元表达式是棒棒哒!
  • 原文地址:https://www.cnblogs.com/liudaihuablogs/p/13463208.html
Copyright © 2011-2022 走看看