【发布时间】:2016-05-19 17:02:54
【问题描述】:
我正在运行一个 Django 项目,我希望 Gunicorn 和 Nginx 为这个项目提供服务。 我正在使用 Gunicorn 19.5。
问题基本上是我的套接字文件没有被创建,我尝试了一切(chmod 777,chown,...)但没有任何工作。
这是我启动 gunicorn 的 bash 脚本:
#!/bin/bash
NAME="hello_project" # Name of the application
DJANGODIR=/home/ubuntu/git/hello_project # Django project directory
SOCKFILE=/home/ubuntu/git/hello_project/run/gunicorn.sock # we will communicte using this unix socket
LOG_FILE=/home/ubuntu/git/hello_project/logs/gunicorn.log
USER=ubuntu # the user to run as
GROUP=ubuntu # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
MAX_REQUESTS=1 # reload the application server for each request
DJANGO_SETTINGS_MODULE=hello_project.settings # which settings file should Django use
DJANGO_WSGI_MODULE=hello_project.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source ~/.virtualenvs/hello_project/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 ~/.virtualenvs/hello_project/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
–name $NAME \
–workers $NUM_WORKERS \
–max-requests $MAX_REQUESTS \
–user=$USER –group=$GROUP \
–bind=unix:$SOCKFILE \
–log-level=debug \
–log-file=$LOG_FILE
我在这里疯了,没有可以查看的日志文件,我什至尝试自己创建套接字文件但没有成功。我怀疑这是一个权限问题,但即使我使用 sudo 运行脚本,它也不起作用。 我的目录“run”被创建了。
这是来自 error.log 文件的 nginx 错误:
2016/05/19 16:56:32 [crit] 11053#0: *28 connect() to unix:/home/ubuntu/git/hello_project/run/gunicorn.sock failed (2: No such file or directory) while connecting to upstream...
有什么线索吗?
非常感谢,
【问题讨论】:
标签: django sockets unix nginx gunicorn