【问题标题】:Nginx, django, gunicorn, ubuntu 14.04 (13: Permission denied) while connecting to upstreamNginx, django, gunicorn, ubuntu 14.04 (13: Permission denied) 同时连接到上游
【发布时间】:2016-08-14 21:14:33
【问题描述】:

我正在使用nginxgunicorn 在我的django 项目中工作,正如这里所说:

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

我的网站在本地工作,但是当我启动 nginxgunicorn 服务器时,我有

502 网关错误。

操作系统是UBUNTU 14.04

我正在尝试使我的项目正常运行,并以 root 身份重新安装所有内容(我知道这很糟糕)——同样的错误。

这是我的“error.log”:

2016/04/20 20:15:10 [crit] 10119#0: *1 connect() to
unix:/root/myproject/myproject.sock 失败(13:权限被拒绝) 连接上游时,客户端: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

description "Gunicorn application server handling myproject" start on runlevel [2345] stop on runlevel [!2345] respawn 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;
}

}

非常感谢您的帮助!!!

【问题讨论】:

    标签: python django unix ubuntu nginx


    【解决方案1】:

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

    您必须弄清楚该进程是什么,并在不需要时终止它。或者使用其他端口。

    【讨论】:

    • 我希望这是真的,但是:# netstat -tulpn | grep :80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15830/nginx
    • 当我终止该进程时,我的网站完全停止工作。
    【解决方案2】:
    proxy_pass http://unix:/root/myproject/myproject.sock;
    

    套接字位于超级用户的主文件夹中。包括您的 nginx 用户在内的所有其他用户几乎都无法访问。请把插座换到不同的位置。 /var/log/gunicorn/ 是个好地方。

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

    setuid root
    

    请在此处使用其他用户。

    【讨论】:

      猜你喜欢
      • 2015-03-29
      • 2016-03-26
      • 2015-07-14
      • 2017-10-18
      • 2016-06-06
      • 2013-08-31
      • 2015-10-22
      • 1970-01-01
      相关资源
      最近更新 更多