Django 部署 uwsgi + nginx + supervisor

Posted BioMarkerInfo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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,待添加。


以上是关于Django 部署 uwsgi + nginx + supervisor的主要内容,如果未能解决你的问题,请参考以下文章

Nginx+uWSGI+Django部署web服务器

[部署开发环境]部署django的生成环境nginx+uwsgi+django

Django + Uwsgi + Nginx 实现生产环境部署

Django + Uwsgi + Nginx 实现生产环境部署

Django3.0 + nginx + uwsgi 部署

uWSGI + Nginx + Django 部署