首页 > 解决方案 > gunicorn:错误:参数--error-logfile/--log-file:预期一个参数

问题描述

我正在尝试制作一个 gunicorn bash 可执行文件来运行 django 服务器,但出现错误 - gunicorn: error: argument --error-logfile/--log-file: expected one argument.

它可以正常工作 -gunicorn bekaim_pre_registration.wsgi:application --bind 0.0.0.0:8001 但 bash 文件出错。

这是我的 -gunicorn_start.bash

#!/bin/bash

NAME="django_app"                                   # Name of the application
DJANGODIR=/home/ubuntu/bekaim_pre_registration               # Django project directory
SOCKFILE=/home/ubuntu/django_env/run/gunicorn.sock  # we will communicte using this unix socket
USER=ubuntu                                         # the user to run as
GROUP=ubuntu                                        # the group to run as
NUM_WORKERS=3                                       # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=bekaim_pre_registration.settings      # which settings file should Django use
DJANGO_WSGI_MODULE=bekaim_pre_registration.wsgi              # WSGI module name
echo "Starting $NAME as `whoami`"

# Activate the virtual environment

cd $DJANGODIR
source /home/ubuntu/django_env/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
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)

exec gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE \
  --log-level=debug \
  --log-file

使该脚本可执行。

$ sudo chmod u+x gunicorn_start.bash

当我测试 -./gunicorn_start.bash

Starting django_app as ubuntu
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: argument --error-logfile/--log-file: expected one argument

我正在关注本教程 - https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html

任何人都可以帮忙吗?

标签: djangobashubuntugunicorn

解决方案


实际上日志文件没有在配置中定义 -

#!/bin/bash

NAME="django_app"                                   # Name of the application
DJANGODIR=/home/ubuntu/bekaim_pre_registration               # Django project directory
SOCKFILE=/home/ubuntu/django_env/run/gunicorn.sock  # we will communicte using this unix socket
USER=ubuntu                                         # the user to run as
GROUP=ubuntu                                        # the group to run as
NUM_WORKERS=3                                       # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=bekaim_pre_registration.settings      # which settings file should Django use
DJANGO_WSGI_MODULE=bekaim_pre_registration.wsgi              # WSGI module name
echo "Starting $NAME as `whoami`"

# Activate the virtual environment

cd $DJANGODIR
source /home/ubuntu/django_env/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
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)

exec gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE \
  --log-level=debug \
  --log-file=-

推荐阅读