Nginx、Django、Gunicorn、Ubuntu 14.04:连接上游时出现“13:Permission denied”的错误提示。

4

我正在使用nginxgunicorn开发我的django项目,参考这里的教程:

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

我的网站在本地工作正常,但是当我启动nginxgunicorn服务器时,出现了

502 Bad Gateway错误。

我的操作系统是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

描述“Gunicorn应用程序服务器处理我的项目” 在运行等级[2345]上启动 在运行等级[!2345]上停止 重新生成 设置用户ID为root 设置组ID为www-data 更改目录为/root/myproject 执行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;
}

是HTML标签之一,用于结束一个段落的定义。在HTML文档中,段落通常用于分隔和组织内容,使其更易于阅读和理解。
2个回答

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

套接字位于超级用户的主文件夹中,其他用户(包括您的nginx用户)几乎无法访问。请将套接字移动到其他位置。/var/log/gunicorn/ 是一个不错的选择。
另外,我看到你正在以root身份运行gunicorn?这是不推荐的做法。
setuid root

请在这里使用其他用户。

0

根据您的nginx错误日志,我认为您有其他进程正在使用端口80。

您需要找出该进程是什么,并在不需要时将其关闭。或者使用另一个端口。


我希望这是真的,但是:# netstat -tulpn | grep :80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15830/nginx - Learn to Fly
当我杀死该进程时,我的网站完全停止工作。 - Learn to Fly

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接