• nginx 代理flask应用的uwsgi配置


    socket代理配置:

    关于uwsgi的用法,请自行百度,这里只针对socket文件和端口的不同,进行单一的记录。

    这种方式启动的flask应用,由于是通过socket与nginx通信的,所以必须制定socket文件,无法进行集群部署:

    uwsgi配置

    [uwsgi]
    #application's base folder
    base = /data/www/myproject
    
    #python module to import
    app = manage
    module = %(app)
    
    home = %(base)/venv
    pythonpath = %(base)
    
    #socket file's location
    socket = /data/www/myproject/%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 = /data/www/log/uwsgi/%n.log

    nginx配置:

    server {
        listen      80;
        server_name localhost;
        charset     utf-8;
        client_max_body_size 75M;
        location / {
            include uwsgi_params;
            uwsgi_pass unix:/data/www/myproject/myproject_uwsgi.sock;
        }
    }

    socket端口配置:

    如果需要使用集群,需要使用端口来与nginx进行通信,那么uwsgi的配置就会有些许的差异:

    uwsgi配置

    [uwsgi]
    #application's base folder
    base = /data/www/myproject
    
    #python module to import
    app = hello
    module = %(app)
    
    home = %(base)/venv
    pythonpath = %(base)
    
    #socket file's location
    socket = :8080
    #socket = /data/www/myproject/%n.sock
    #permissions for the socket file
    chmod-socket    = 644
    #the variable that holds a flask application inside the module imported at line #6
    callable = app
    #location of log files
    logto = /data/www/log/uwsgi/%n.log

    差异就是将sock文件,改为端口,当然也可以写成如下格式:

    socket = 0.0.0.0:8080
    socket = 127.0.0.1:8080

    那么如果nginx需要负载两台甚至多台server,就需要修改配置:

    upstream ai-server {
            server server1:8080;
            server server2:8080;
    }
    server {
        listen      80;
        server_name localhost;
        charset     utf-8;
        client_max_body_size 75M;
    
        location / {
            include uwsgi_params;
            uwsgi_pass ai-server;
        }
    }
  • 相关阅读:
    C# 托管内存与非托管内存之间的转换
    A*算法详解链接
    【转】使用minizip解压缩多个文件(基于zlib)
    lua中table的遍历,以及删除
    clientHeight scrollHeight offsetHeight
    消息中间件(转)
    js 原型链和继承(转)
    session 和 cookie (转)
    java servlet
    redis 命令
  • 原文地址:https://www.cnblogs.com/slim-liu/p/9950339.html
Copyright © 2020-2023  润新知