【问题标题】:502 error with nginx + uwsgi +djangonginx + uwsgi +django 出现 502 错误
【发布时间】:2012-07-10 22:12:31
【问题描述】:

我尝试在 nginx 和 uwsgi 上配置 django,尝试访问 localhost 时遇到 502 bad gateway 错误

这是我的 /etc/ngingx/sites-available/默认文件

server {
    server_name testapp1.com www.testapp1.com;
    access_log /var/log/nginx/testapp1.com.access.log;

    location / {
        uwsgi_pass unix:///var/run/uwsgi/app/testapp1/socket;
        include uwsgi_params;
    }
}

这是我在 /etc/nginx/apps-available/ 中的 testapp1.ini 文件

[uwsgi]  
    thread=3  
    master=1  
    env = DJANGO_SETTINGS_MODULE=testapp1.settings  
    module = django.core.handlers.wsgi:WSGIHandler()  
    chdir = /home/paul/apps/testapp1  
    socket = /run/uwsgi/testapp1/socket  
    logto = /var/log/uwsgi/testapp1.log  

这是 uwsgi.log 文件

2012 年 7 月 10 日星期二 21:49:38 - *** 开始 uWSGI 1.0.3-debian(32 位)
[2012 年 7 月 10 日星期二 21:49:38] *** 2012 年 7 月 10 日星期二 21:49:38 - 编译
版本:4.6.2 2012 年 2 月 20 日 10:06:16 Tue Jul 10 21:49:38
2012 - 当前工作目录:/Tue Jul 10 21:49:38 2012 - 写作
pidfile 到 /run/uwsgi/app/testapp1/pid 2012 年 7 月 10 日星期二 21:49:38 -
检测到的二进制路径:/usr/bin/uwsgi-core Tue Jul 10 21:49:38 2012 -
setgid() 至 2012 年 7 月 10 日星期二 21:49:38 至 33 日 - setuid() 至 2012 年 7 月 10 日星期二 33 日
2012 年 21:49:38 - 您的内存页面大小为 4096 字节,周二 7 月 10 日
2012 年 21:49:38 - uwsgi 套接字 0 绑定到 UNIX 地址
/run/uwsgi/app/testapp1/socket fd 5 Tue Jul 10 21:49:38 2012 - bind():
没有这样的文件或目录 [socket.c line 107]

我没有更改 nginx.conf 文件。

【问题讨论】:

  • 请发布 nginx 日志。 nginx 很可能无法连接到 uWSGI。在这种情况下,要么使用端口,要么使用fix permissions
  • 这些套接字定义是否相同?

标签: django nginx uwsgi


【解决方案1】:

错误信息已经够清楚了:

Tue Jul 10 21:49:38 2012 - uwsgi socket 0 bound to UNIX address
/run/uwsgi/app/testapp1/socket fd 5
Tue Jul 10 21:49:38 2012 - bind():
No such file or directory [socket.c line 107]

你看到以下之间的区别:

 socket = /run/uwsgi/testapp1/socket

和:

 uwsgi_pass unix:///var/run/uwsgi/app/testapp1/socket;

?

提示: /var/run/uwsgi/app/testapp1/socket

【讨论】:

  • 抱歉回复晚了 - 是的,我给套接字文件提供不同路径是一个愚蠢的错误 - 复制粘贴问题:)
【解决方案2】:

其他情况是权限问题(不是像您的情况那样的套接字路径拼写错误)。在这种情况下,您可以将其添加到 uwsgi ini 文件中

[uwsgi]                                                                                                          
uid = www-data
gid = www-data
chmod-socket = 664
chown-socket = www-data

【讨论】:

  • 我需要这个chown-socket = www-data,但我一辈子都想不通!谢谢你!作为旁注,我认为将套接字的文件权限设置为 664(或最多 666)就足够了。
  • @zzart :我已经复制了这个设置,但是套接字仍然是由登录用户而不是 www-data 创建的。另外,uwsgi 启动失败,报错chown(): Operation not permitted
  • @buffer 我还发现你不能在uwsgi.ini中使用chown-socket
猜你喜欢
  • 2016-02-16
  • 2019-01-01
  • 2015-04-10
  • 2015-04-30
  • 1970-01-01
  • 2020-10-29
  • 2018-11-12
  • 2020-06-29
  • 1970-01-01
相关资源
最近更新 更多