【问题标题】:Could not run nginx with gunicorn, getting permission denied error while connecting to upstream无法使用 gunicorn 运行 nginx,连接到上游时出现权限被拒绝错误
【发布时间】:2014-10-31 06:17:34
【问题描述】:

我用 nginx 和 gunicorn 托管了 django。我收到以下错误。

# 1 connect() to 127.0.0.1:8001 failed (13: Permission denied) while connecting to upstream, client: 106.77.61.123, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8001/favicon.ico", host: "<domainname>

[相同的配置在我的本地 centos 机器上运行]

但在 VPS 托管环境 (vps) 上:

我正在使用用户名为“ftpuser1”的centos-7(nginx.conf中的用户名是“ftpuser1”)。

我正在使用用户“ftpuser1”运行 nginx

/var/cache/nginx 的所有者是“ftpuser1”,具有 777 递归权限

源代码路径的所有者也是“ftpuser1”,具有777递归权限

这是我的 /etc/nginx/conf.d/default.config 配置文件内容:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /home/ftpuser1/donation/templates;
        index  home.html;
        proxy_pass http://127.0.0.1:8001;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #} }

谁能帮我解决这个问题?

【问题讨论】:

  • netstat -tulpn | grep 8001检查那个端口上是否有其他东西在运行

标签: django nginx centos


【解决方案1】:
  1. 修复配置末尾的右括号“}”(不是问题)
  2. 尝试输入“user ftpuser1;”在“服务器{..}”之前的配置顶部

【讨论】:

  • 1.已经关闭了,在复制粘贴其他编辑器时到了一行以上,错误地显示评论,它没有评论,它正确关闭。 2.在nginx.conf用户ftpuse1已经存在
  • 那可能是你创建的时候用户本身没有权限?
【解决方案2】:

此错误消息意味着,如果您在 linux 环境中,您没有对服务于“favicon.ico”的根文件夹的读写权限;

试试这个命令:sudo chmod 775 /&lt;foldername&gt;

不要忘记命令开头的sudo

然后在你申请权限后尝试重启你的 *nginx 服务器

【讨论】:

  • 我将源代码的权限递归更改为777,所有者是ftpuser1。我重新启动了nginx,但问题仍然存在。
猜你喜欢
  • 2018-09-13
  • 2015-07-04
  • 2015-07-14
  • 2016-05-12
  • 2014-03-16
  • 2014-07-19
  • 2022-01-03
  • 2017-10-18
  • 1970-01-01
相关资源
最近更新 更多