Django Gunicorn Nginx

2021-01-22 18:05:23 浏览数 (2)

Maybe even better than uwsgi, assume the django project in PRJ_NAME

代码语言:shell复制
pip install gunicorn
cd PRJ_NAME
gunicorn -w 2 PRJ_NAME.wsgi:application --bind 0.0.0.0:8000

try more

代码语言:shell复制
#!/bin/bash
# 项目的目录
DJANGODIR=/Users/workspace/hello_django/
# 应用名称
PRJNAME='PRJ_NAME'

# USER=root # --user=$USER --group=$GROUP 
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=$PRJNAME.settings
DJANGO_WSGI_MODULE=$PRJNAME.wsgi
LOG_DIR=$DJANGODIR/deploy

# 激活Python运行环境
cd $DJANGODIR
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# 启动Django
exec gunicorn ${DJANGO_WSGI_MODULE}:application 
    --name $PRJNAME 
    --workers $NUM_WORKERS 
    --log-level=debug 
    --bind='127.0.0.1:8000' 
    --access-logfile=${LOG_DIR}/gunicorn_access.log

execute

代码语言:shell复制
nohup ./deploy/gunicorn.sh >./deploy/gunicorn.out 2>&1 &

nginx

代码语言:text复制
server {
       listen  80;
       server_name  localhost;
       charset utf-8;
       location / {
          proxy_pass http://127.0.0.1:8000;
       }
}

check

代码语言:javascript复制
open http://localhost

Done

0 人点赞