• python flask socketio uwsgi和nginx supervisor配置方式


    uwsgi

    # copy it to folder: /app/test/
    [uwsgi]
    socket = 0.0.0.0:23489
    processes = 1
    threads = 1
    master = true
    pythonpath = /app/test/test
    module = web_app
    callable = webapp
    env = pickwant_WSAPP=True
    env = MONKEY_PATCH=YES
    buffer-size = 32768
    logto = /app/test/logs/uwsgi/pickwant_ws.log
    pidfile = /app/pickwant/logs/uwsgi/pickwant_ws_uwsgi.pid
    #memory-report = true
    gevent=400
    gevent-monkey-patch=true

    nginx

    upstream test {
         server 127.0.0.1:23488;
    }
    
    upstream test_ws {
         server 127.0.0.1:23489;
    }
    
    upstream test_admin {
         server 127.0.0.1:23490;
    }
    
    server {
        listen       443  ssl;
        server_name  api.test.com;
        client_max_body_size 512m;
        ssl                  on;
        ssl_certificate      /app/test/certs/api.test.com.crt;
        ssl_certificate_key  /app/test/certs/api.test.com.key;
        access_log  /app/pickwant/logs/nginx/api_test_access.log  main;
        error_log  /app/pickwant/logs/nginx/api_test_error.log;
    
        location / {
            include test_params;
            uwsgi_pass test;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    
        location /socket.io {
            include uwsgi_params;
            uwsgi_pass test_ws;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 300s;
    
            add_header Access-Control-Allow-Headers "X-Requested-With,Authorization";
            add_header Access-Control-Allow-Methods "GET,POST,OPTIONS";
        }
    
        location ~ /admin {
            include uwsgi_params;
            proxy_pass http://test_admin;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    
        location ~ MP_verify.*\.txt { # 腾讯公众号域名验证用
            root /app/test/pickwant/static;
        }
    }
    
    server {
        listen 80;
        server_name api.test.com;
    
       #核心代码
        rewrite ^(.*)$ https://${server_name}$1 permanent;
    }
    
    server {
        listen       443  ssl;
        server_name  www.test.com;
        client_max_body_size 512m;
        ssl                  on;
        ssl_certificate      /app/test/certs/www.test.com.crt;
        ssl_certificate_key  /app/test/certs/www.test.com.key;
    
        access_log  /app/pickwant/logs/nginx/test.log  main;
        error_log  /app/test/logs/nginx/test.log;
    
        location / {
            add_header Access-Control-Allow-Methods *;
            add_header Access-Control-Max-Age 3600;
            add_header Access-Control-Allow-Credentials true;
            add_header Access-Control-Allow-Origin *;
            root /app/test/web/pages;
            index index.html;
        }
    
        location /.git {
            root html;
            deny all;
            return 403;
        }
    
    }
    
    server {
        listen 80;
        server_name www.test.com;
    
       #核心代码
        rewrite ^(.*)$ https://${server_name}$1 permanent;
    }

    supervisor

    [program:test]
    command=/app/test/pwenv/bin/uwsgi -i /app/test/test/scripts/conf_files/test_uwsgi.ini
    process_name=%(program_name)s
    numprocs=1                    ; number of processes copies to start (def 1)
    directory=/app/test           ; directory to cwd to before exec (def no cwd)
    umask=022                     ; umask for process (default None)
    priority=999                  ; the relative start priority (default 999)
    autostart=true                ; start at supervisord start (default: true)
    startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
    startretries=3                ; max # of serial start failures when starting (default 3)
    autorestart=unexpected        ; when to restart if exited after running (def: unexpected)
    exitcodes=0,2                 ; 'expected' exit codes used with autorestart (default 0,2)
    stopsignal=TERM               ; signal used to kill process (default TERM)
    stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
    stopasgroup=false             ; send stop signal to the UNIX process group (default false)
    killasgroup=false             ; SIGKILL the UNIX process group (def false)
    ;user=nginx                    ; setuid to this UNIX account to run the program
    redirect_stderr=true          ; redirect proc stderr to stdout (default false)
    stdout_logfile=/app/test/logs/uwsgi/uwsgi_test.log
    stdout_logfile_maxbytes=20MB   ; max # logfile bytes b4 rotation (default 50MB)
    stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
    stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
    stdout_events_enabled=false   ; emit events on stdout writes (default false)
    
    
    [program:test-ws]
    command=/app/test/pwenv/bin/uwsgi /app/test/test/scripts/conf_files/test_ws_uwsgi.ini
    process_name=%(program_name)s
    numprocs=1                    ; number of processes copies to start (def 1)
    directory=/app/test           ; directory to cwd to before exec (def no cwd)
    umask=022                     ; umask for process (default None)
    priority=999                  ; the relative start priority (default 999)
    autostart=true                ; start at supervisord start (default: true)
    startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
    startretries=3                ; max # of serial start failures when starting (default 3)
    autorestart=unexpected        ; when to restart if exited after running (def: unexpected)
    exitcodes=0,2                 ; 'expected' exit codes used with autorestart (default 0,2)
    stopsignal=TERM               ; signal used to kill process (default TERM)
    stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
    stopasgroup=false             ; send stop signal to the UNIX process group (default false)
    killasgroup=false             ; SIGKILL the UNIX process group (def false)
    ;user=nginx                    ; setuid to this UNIX account to run the program
    redirect_stderr=true          ; redirect proc stderr to stdout (default false)
    stdout_logfile=/app/test/logs/uwsgi/uwsgi_test_ws.log
    stdout_logfile_maxbytes=20MB   ; max # logfile bytes b4 rotation (default 50MB)
    stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
    stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
    stdout_events_enabled=false   ; emit events on stdout writes (default false)
    
    [program:test-admin]
    command=/app/test/pwenv/bin/python /app/test/test/admin_run.py -p 23490
    process_name=%(program_name)s
    numprocs=1                    ; number of processes copies to start (def 1)
    directory=/app/test           ; directory to cwd to before exec (def no cwd)
    umask=022                     ; umask for process (default None)
    priority=999                  ; the relative start priority (default 999)
    autostart=true                ; start at supervisord start (default: true)
    startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
    startretries=3                ; max # of serial start failures when starting (default 3)
    autorestart=unexpected        ; when to restart if exited after running (def: unexpected)
    exitcodes=0,2                 ; 'expected' exit codes used with autorestart (default 0,2)
    stopsignal=TERM               ; signal used to kill process (default TERM)
    stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
    stopasgroup=false             ; send stop signal to the UNIX process group (default false)
    killasgroup=false             ; SIGKILL the UNIX process group (def false)
    redirect_stderr=true          ; redirect proc stderr to stdout (default false)
    stdout_logfile=/app/test/logs/admin/admin.log
    stdout_logfile_maxbytes=20MB   ; max # logfile bytes b4 rotation (default 50MB)
    stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
    stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
    stdout_events_enabled=false   ; emit events on stdout writes (default false)
  • 相关阅读:
    程序员用实力把公司干倒闭了
    可能是把 Java 接口讲得最通俗的一篇文章
    我去,你竟然还不会用 synchronized
    优秀的程序员真的不写注释吗?
    小白,你要的Java抽象类,操碎了心!
    如何将arcgis的mxd文档存储为相对路径
    解决EditorLineEnds.ttr被锁定导致Delphi2006-2010无法启动的问题
    用EXcel制作不同背景的图
    [转载]: delphi中XLSReadWrite控件的使用(1)---简介
    [转载]: delphi中XLSReadWrite控件的使用(2)---delphi XE下安装
  • 原文地址:https://www.cnblogs.com/zhaoyingjie/p/16440825.html
Copyright © 2020-2023  润新知