nginx 失败(13:权限被拒绝)uwsgi(502 错误网关)

nginx 失败(13:权限被拒绝)uwsgi(502 错误网关)

我在新的 DigitalOcean droplet 上运行我的应用程序时遇到了麻烦。该机器运行的是 CentOS 6.5

我的/etc/nginx/nginx.conf

user  nginx www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;
(continues)

我的myapp_nginx.conf

server {

   server_name 104.xxx.x.xxx;
    listen      8080;
    charset     utf-8;
    client_max_body_size 30M;

    location / {
        index index.html index.htm;
        root /home/webdev/mydevelopment/git/ers_portal;
        try_files $uri @app;
    }

    location /static {
    alias /home/webdev/mydevelopment/git/ers_portal/app/static;
    }

    location @app {
        include uwsgi_params;
        uwsgi_pass unix:/home/webdev/mydevelopment/git/ers_portal_uwsgi.sock;
    }
}

我的myapp_uwsgi.ini

[uwsgi]
master = true
#user info
uid = webdev
gid = www-data

#application's base folder
base = /home/webdev/mydevelopment/git/ers_portal

#chdir to this folder when starting
#chdir = /home/webdev/mydevelopment/git/ers_portal

#python module to import
app = run_web
module = %(app)

home = /home/webdev/mydevelopment/venvs/ecodev_do
pythonpath = %(base)

#socket file's location
socket = /home/webdev/mydevelopment/git/ers_portal/%n.sock

#permissions for the socket file
chmod-socket    = 666

#the variable that holds a flask application inside the module imported at line #6
#uwsgi varible only, does not relate to your flask application
callable = app

#location of log files
logto = /home/webdev/mydevelopment/git/ers_portal/logs/%n.log

error.log每当我向以下对象发出 Web 请求时,nginx 中都会打印错误消息:104.xxx.x.xxx:8080

2014/11/19 23:14:47 [crit] 28090#0: *1 stat() "/home/webdev/mydevelopment/git/ers_portal/favicon.ico" failed (13: Permission denied), client: 71.211.xxx.xxx, server: 104.xxx.x.xxx, request: "GET /favicon.ico HTTP/1.1", host: "104.xxx.x.xxx:8080"
2014/11/19 23:14:47 [crit] 28090#0: *1 connect() to unix:/home/webdev/mydevelopment/git/ers_portal_uwsgi.sock failed (13: Permission denied) while connecting to upstream, client: 71.211.xxx.xxx, server: 104.xxx.x.xxx, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:/home/webdev/mydevelopment/git/ers_portal_uwsgi.sock:", host: "104.xxx.x.xxx:8080"

项目文件夹:drwxr-xr-x 6 webdev www-data 4.0K Nov 19 23:40 ers_portal

该文件夹内的套接字:srw-rw-rw- 1 webdev www-data 0 Nov 19 23:45 ers_portal_uwsgi.sock

如果您需要任何其他信息,请告诉我。谢谢!

编辑

我按照@Eugene的建议更改了权限。现在我/var/log/nginx/access.log看到

[20/Nov/2014:01:37:58 -0500] "GET / HTTP/1.1" 502 574 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" "-"

/var/log/nginx/error.log我看来

2014/11/20 01:38:27 [crit] 28639#0: *1 connect() to unix:/home/webdev/mydevelopment/git/ers_portal_uwsgi.sock failed (2: No such file or directory) while connecting to upstream, client: 71.21.my.local.ip, server: , request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/home/webdev/mydevelopment/git/ers_portal_uwsgi.sock:", host: "104.ser.ver.ip"

之前的 favicon.ico 拒绝(如下)var/log/nginx/access.log不再显示

"GET /favicon.ico HTTP/1.1" 502 574 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" "-"

答案1

解决了

经过几个小时的搜索,我终于找到了我的拼写错误。在/path/to/my/webapp/my_app_nginx.conf以下行中

location @app {
        include uwsgi_params;
        uwsgi_pass unix:/home/webdev/mydevelopment/git/ers_portal_uwsgi.sock;
    }

应该读

location @app {
        include uwsgi_params;
        uwsgi_pass unix:/home/webdev/mydevelopment/git/ers_portal/ers_portal_uwsgi.sock;
    }

另外,/etc/nginx/nginx.confuser nginx www-data;user nginx;

还要确保“顶层”中没有/etc/nginx/nginx.conf与您的应用程序配置冲突的默认服务器块(在我的情况下/path/to/my/webapp/my_app_nginx.conf,它是符号链接到/etc/nginx/conf.d/文件夹)。

得到教训...

  1. 不要气馁。世界上最糟糕(也许是第二糟糕)的感觉就是在很长一段时间内都无法弄清楚某件事。尤其是如果这是你的爱好,你很容易觉得自己能力不足,这件事太难了,你还不够好。坚持下去。
  2. 有条不紊。我变得疯狂地追求改变,尤其是在最后。这导致我上床睡觉时没有真正的进展,醒来时又回到了原来的位置。把所有事情都写下来,记录你尝试过的事情,并跟踪以前的更改。如果ABABA是工作配置,并且---B-是你要寻找的更改,但你忘了改--B----A--,你就会不断重复。参见#1
  3. 记住,有时找到解决方案最重要的方法就是站起来,走开。
  4. 不要低估你的同行(这个社区)的知识。虽然他们可能无法立即解决你的特定问题,但请记住我们每个人都不是傻子(或类似的愚蠢说法)。我们都热衷于从地球上逐一清除问题。

答案2

看起来您在路径上的某个地方没有适当的权限/home/webdev/mydevelopment/git/ers_portal- 虽然ers_portal似乎有适当的 755,但有些目录没有。检查从 开始的所有目录/是否ers_portal至少有 5 个 www-data 用户或其组或所有人的权限。

答案3

我认为问题出在线路上

 try_files $uri @app;

只需注释掉它并重新启动 nginx 服务器即可。它应该可以解决问题。

相关内容