【问题标题】:Gunicorn Socket file is missingGunicorn 套接字文件丢失
【发布时间】: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


    【解决方案1】:

    尝试在不执行 exec ~/.virtualenvs/hello_project/bin/gunicorn 的情况下运行脚本。

    尝试使用 gunicorn 然后使用 args 运行它。

    这是假设您有权在没有 virtualenv 的系统上安装 gunicorn。

    我有一个要点,可以启动您尝试运行的同一进程。 (Django,Nginx,Gunicorn) https://gist.github.com/marcusshepp/129c822e2065e20122d8

    我看到您正在使用 supervisor,因此您不会想使用我在脚本中使用的 --deamon 选项。

    【讨论】:

      猜你喜欢
      • 2015-04-25
      • 2011-05-19
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      • 2015-01-28
      • 2017-02-16
      相关资源
      最近更新 更多