python – 连接到上游时的Nginx,django,gunicorn,ubuntu 14.04(13:权限被拒绝)

我正在使用nginx和gunicorn在我的
django项目上工作,正如它在这里所说:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04

我的网站在本地工作,但是当我启动nginx和gunicorn服务器时

502 Bad Gateway error.

操作系统是UBUNTU 14.04

我正在尝试让我的项目工作,并以root身份重新安装所有内容(我知道它很糟糕) – 同样的错误.

这是我的“error.log”:

2016/04/20 20:15:10 [crit] 10119#0: *1 connect() to
unix:/root/myproject/myproject.sock failed (13: Permission denied)
while connecting to upstream, client: 46.164.23

当我运行命令“nginx”时:

  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] still could not bind()

我的gunicorn.conf

描述“处理myproject的Gunicorn应用服务器”
从运行级别开始[2345]
停在运行级别[!2345]
重生
setuid root
setgid www-data
chdir / root / myproject
exec myprojectenv / bin / gunicorn –workers 3 –bind unix:/root/myproject/myproject.sock myproject.wsgi:application

多数民众赞成我的“/ etc / nginx / sites-available / myproject”

server {
listen 80;
server_name         www.mysite.ru;

error_log /nginx_error.log;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /root/myproject;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/root/myproject/myproject.sock;
}

}

我非常感谢你的帮助!

最佳答案

proxy_pass http://unix:/root/myproject/myproject.sock;

套接字位于超级用户的主文件夹中.对于包括你的nginx用户在内的所有其他用户来说,这几乎是无法访问的.请将插座更多地连接到其他位置. / var / log / gunicorn /是个好地方.

我也看到你以root身份运行gunicorn吗?不建议.

setuid root

请在这里使用其他用户.

点赞