设置django项目时Gunicorn错误203
Gunicorn error 203 while setting up django project
我尝试使用 nginx 和 gunicorn 设置一个 django 项目,但出现 gunicorn 错误 203:
我的安装位于路径 /webapps/sarlex 并且所有项目文件都归用户“sarlex”和组“webapps”所有。
virtualenv 位于 /webapps/sarlex/environment。
Gunicorn 位于 /webapps/sarlex/environment/bin/ 并归用户 sarlex 所有。
Gunicorn 配置设置在 /webapps/sarlex/gunicorn_start.sh:
NAME="sarlex" # Name of the application
DJANGODIR=/webapps/sarlex/ # Django project directory
SOCKFILE=/webapps/sarlex/run/gunicorn.sock # we will communicte using this unix socket
USER=sarlex # the user to run as
GROUP=webapps # the group to run as
NUM_WORKERS=9 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=sarlex.settings # which settings file should Django use
DJANGO_WSGI_MODULE=sarlex.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source /webapps/sarlex/environment/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
执行 gunicorn_start.sh 适用于激活和停用的环境。
/etc/systemd/system/gunicorn.service 由 root 拥有并具有以下内容:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sarlex
Group=webapps
WorkingDirectory=/webapps/sarlex
ExecStart=/webapps/sarlex/gunicorn_start.sh
[Install]
WantedBy=multi-user.target
我尝试用“User=root”替换“User=Sarlex”,但仍然出现同样的错误。
它拍的正确的 gunicorn
感谢您的帮助
你的问题到底是什么?
DJANGO_SETTINGS_MODULE
的导出很尴尬。
- 用双引号将表达式和变量引用括起来
NAME="sarlex" # Name of the application
DJANGODIR=/webapps/sarlex/ # Django project directory
SOCKFILE=/webapps/sarlex/run/gunicorn.sock # we will communicte using this unix socket
USER=sarlex # the user to run as
GROUP=webapps # the group to run as
NUM_WORKERS=9 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=sarlex.settings # which settings file should Django use
DJANGO_WSGI_MODULE=sarlex.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
source /webapps/sarlex/environment/bin/activate
cd "$DJANGODIR"
export DJANGO_SETTINGS_MODULE
export PYTHONPATH="$DJANGODIR":$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR="$(dirname $SOCKFILE)"
test -d "$RUNDIR" || mkdir -p "$RUNDIR"
# Start your Django Unicorn
exec gunicorn "${DJANGO_WSGI_MODULE}:application" \
--name "$NAME" \
--workers "$NUM_WORKERS" \
--user="$USER" --group="$GROUP" \
--bind="unix:$SOCKFILE" \
--log-level=debug \
--log-file=-
请显示 /var/log/nginx/
条错误消息。
Django 启动失败,因为在我的一个脚本中,我在路径中写了“admin”而不是“Admin”。
这并没有在我正在开发代码的 windows PC 上造成问题。
我尝试使用 nginx 和 gunicorn 设置一个 django 项目,但出现 gunicorn 错误 203:
我的安装位于路径 /webapps/sarlex 并且所有项目文件都归用户“sarlex”和组“webapps”所有。 virtualenv 位于 /webapps/sarlex/environment。 Gunicorn 位于 /webapps/sarlex/environment/bin/ 并归用户 sarlex 所有。
Gunicorn 配置设置在 /webapps/sarlex/gunicorn_start.sh:
NAME="sarlex" # Name of the application
DJANGODIR=/webapps/sarlex/ # Django project directory
SOCKFILE=/webapps/sarlex/run/gunicorn.sock # we will communicte using this unix socket
USER=sarlex # the user to run as
GROUP=webapps # the group to run as
NUM_WORKERS=9 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=sarlex.settings # which settings file should Django use
DJANGO_WSGI_MODULE=sarlex.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source /webapps/sarlex/environment/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
执行 gunicorn_start.sh 适用于激活和停用的环境。
/etc/systemd/system/gunicorn.service 由 root 拥有并具有以下内容:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sarlex
Group=webapps
WorkingDirectory=/webapps/sarlex
ExecStart=/webapps/sarlex/gunicorn_start.sh
[Install]
WantedBy=multi-user.target
我尝试用“User=root”替换“User=Sarlex”,但仍然出现同样的错误。
它拍的正确的 gunicorn
感谢您的帮助
你的问题到底是什么?
DJANGO_SETTINGS_MODULE
的导出很尴尬。- 用双引号将表达式和变量引用括起来
NAME="sarlex" # Name of the application
DJANGODIR=/webapps/sarlex/ # Django project directory
SOCKFILE=/webapps/sarlex/run/gunicorn.sock # we will communicte using this unix socket
USER=sarlex # the user to run as
GROUP=webapps # the group to run as
NUM_WORKERS=9 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=sarlex.settings # which settings file should Django use
DJANGO_WSGI_MODULE=sarlex.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
source /webapps/sarlex/environment/bin/activate
cd "$DJANGODIR"
export DJANGO_SETTINGS_MODULE
export PYTHONPATH="$DJANGODIR":$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR="$(dirname $SOCKFILE)"
test -d "$RUNDIR" || mkdir -p "$RUNDIR"
# Start your Django Unicorn
exec gunicorn "${DJANGO_WSGI_MODULE}:application" \
--name "$NAME" \
--workers "$NUM_WORKERS" \
--user="$USER" --group="$GROUP" \
--bind="unix:$SOCKFILE" \
--log-level=debug \
--log-file=-
请显示 /var/log/nginx/
条错误消息。
Django 启动失败,因为在我的一个脚本中,我在路径中写了“admin”而不是“Admin”。 这并没有在我正在开发代码的 windows PC 上造成问题。