gpt4 book ai didi

django - 502 Bad Gateway - django + nginx + gunicorn - socks 失败(13 : Permission denied)

转载 作者:行者123 更新时间:2023-12-03 18:03:15 27 4
gpt4 key购买 nike

我正在关注本教程:https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04

我相信我的设置中的其他一切都是正确的。文件/var/log/nginx/error.log 有许多以下错误:

2015/12/19 18:41:58 [crit] 10850#0: *23 connect() to unix:/home/root/myproject/myproject.sock 失败 (13: 权限被拒绝) 连接上游时,客户端:[[my ip]],服务器:[[server ip]],请求:“GET/HTTP/1.1”,上游:“http://unix:/home/root/myproject/myproject.sock:/”,主机:“[[server ip]] ”

命令:

/home/root/myproject ls -l /home/root/classNote/classNote.sock

输出:
srwxrwxrwx 1 root www-data 0 Dec 19 18:17 /home/root/myproject/myproject.sock

编辑:安德烈的评论回应:

命令:
ps ax | grep gunicorn

输出:
  847 ?        Ss     0:00 /home/root/myproject/myprojectEnv/bin/python myprojectEnv/bin/gunicorn --workers 3 --bind unix:/home/root/myproject/myproject.sock myproject.wsgi:application
921 ? S 0:00 /home/root/myproject/myprojectEnv/bin/python myprojectEnv/bin/gunicorn --workers 3 --bind unix:/home/root/myproject/myproject.sock myproject.wsgi:application
923 ? S 0:00 /home/root/myproject/myprojectEnv/bin/python myprojectEnv/bin/gunicorn --workers 3 --bind unix:/home/root/myproject/myproject.sock myproject.wsgi:application
928 ? S 0:00 /home/root/myproject/myprojectEnv/bin/python myprojectEnv/bin/gunicorn --workers 3 --bind unix:/home/root/myproject/myproject.sock myproject.wsgi:application
1136 pts/0 S+ 0:00 grep gunicorn

最佳答案

似乎存在权限问题以 root 身份启动您的 nginx 服务,因为 root 有权访问您的 my project.sock

sudo service nginx stop

然后
 sudo service nginx start

但是以root身份启动nginx并不是一个好主意。您可以尝试更改当前用户的权限

我可以建议你一个工作正常的替代方案。
让一个 shell 脚本来处理这一切。
像这样创建一个shell脚本(*表示在注释中是必需的)
#!/bin/bash

NAME="" #Name of the application (*)
DJANGODIR=/path/to/django/project # Django project directory (*)
SOCKFILE=/path/to/socket/file/myproject.sock # we will communicate using this unix socket (*)
USER= # the user to run as (*)
GROUP= # the group to run as (*)
NUM_WORKERS=1 # how many worker processes should Gunicorn spawn (*)
DJANGO_SETTINGS_MODULE=yourproject.settings # which settings file should Django use (*)
DJANGO_WSGI_MODULE=yourproject.wsgi # WSGI module name (*)

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source /path/to/virtualenv/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 /path/to/virtualenv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user $USER \
--bind=unix:$SOCKFILE

关于django - 502 Bad Gateway - django + nginx + gunicorn - socks 失败(13 : Permission denied),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34376636/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com