• Django 部署 uwsgi + nginx + supervisor


    Django 部署 uwsgi + nginx + supervisor

    https://hacpai.com/article/1460607620615?p=1&m=0

    更新依赖

    pip install uwsgi
    

    编辑配置文件 uwsgi.ini

    [uwsgi]
    # Django-related settings
    chdir           = /home/zonghua/Documents/test_project
    module          = test_project.wsgi:application
    env             = DJANGO_SETTINGS_MODULE=test_project.settings_production
    home            = /home/zonghua/Documents/test_project/venv
    reload-mercy    = 10
    user            = zonghua
    uid             = zonghua
    pcre-jit
    thunder-lock
    enable-threads
    master          = True
    threads         = 2
    processes       = 4
    socket          = 127.0.0.1:8001
    chmod-socket    = 664
    vacuum          = true
    

    执行命令

    uwsgi --ini uwsgi.ini 
    

    运行情况

    [uwsgi](https://hacpai.com/tag/uwsgi) getting INI configuration from /home/zonghua/Documents/test_project/uwsgi.ini
    *** Starting uWSGI 2.0.12 (64bit) on [Tue Apr  5 13:59:02 2016] ***
    compiled with version: 5.2.1 20151010 on 04 April 2016 01:12:07
    os: Linux-4.2.0-34-generic #39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016
    nodename: x
    machine: x86_64
    clock source: unix
    pcre jit enabled
    detected number of CPU cores: 4
    current working directory: /home/zonghua/Documents/test_project
    detected binary path: /home/zonghua/Documents/test_project/venv/bin/uwsgi
    chdir() to /home/zonghua/Documents/test_project
    your processes number limit is 11829
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    thunder lock: enabled
    uwsgi socket 0 bound to TCP address 127.0.0.1:8001 fd 3
    Python version: 2.7.10 (default, Oct 14 2015, 16:09:02)  [GCC 5.2.1 20151010]
    Set PythonHome to /home/zonghua/Documents/test_project/venv
    Python main interpreter initialized at 0x93b180
    python threads support enabled
    your server socket listen backlog is limited to 100 connections
    your mercy for graceful operations on workers is 60 seconds
    mapped 415360 bytes (405 KB) for 8 cores
    *** Operational MODE: preforking+threaded ***
    WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x93b180 pid: 2781 (default app)
    *** uWSGI is running in multiple interpreter mode ***
    spawned uWSGI master process (pid: 2781)
    spawned uWSGI worker 1 (pid: 2784, cores: 2)
    spawned uWSGI worker 2 (pid: 2785, cores: 2)
    spawned uWSGI worker 3 (pid: 2787, cores: 2)
    spawned uWSGI worker 4 (pid: 2789, cores: 2)
    

    nginx 配置 文件 /etc/nginx/site-avaiable/test

    server {
        listen 80;
        charset utf-8;
        client_max_body_size 75M;
        location /media {
            alias /path/to/project/media;
        }
        location /static {
           alias /path/to/project/static;
       }
        location / {
            uwsgi_pass 127.0.0.1:8001;
            include uwsgi_params;
        }
    }
    

    supervisor 配置文件 /etc/supervisor/supervisor.conf

    [program:test]
    directory= /home/zonghua/Documents/test_project
    command = /home/zonghua/Documents/test_project/venv/bin/uwsgi --ini /home/zonghua/Documents/test_project/uwsgi.ini
    user = zonghua
    autostart = true
    autorestart = true
    stopsignal = QUIT
    redirect_stderr = true
    loglevel = error
    stdout_logfile = /home/zonghua/Documents/test_project/logs/uwsgi_out.log
    stderr_logfile = /home/zonghua/Documents/test_project/logs/uwsgi_err.log
    logfile_maxbytes = 1M
    

    热加载需要指定一个 pidfile,待添加。

  • 相关阅读:
    机器学习【工具】:Numpy
    机器学习【算法】:KNN近邻
    【笔记】:字典内部剖析
    【笔记】:谁偷了我的内存?
    什么是RESTful框架
    音频下载服务
    【模块】:Requests(二)
    【模块】:Weakref
    异步Web服务(二)
    【Win10】UAP/UWP/通用 开发之 RelativePanel
  • 原文地址:https://www.cnblogs.com/xiaojikuaipao/p/5989003.html
Copyright © 2020-2023  润新知