Python Django + Nginx + uwsgi 502 Bad Gateway

问题描述 投票:0回答:2

Centos7,当我连接到我的网站时,显示502 Bad Gateway, 我用命令测试我的网站 uwsgi --ini systemctl启动nginx 我无法弄清楚发生了什么,请帮助我!

这是nginx.conf

upstream django {
  server 127.0.0.1:8000;
}

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  example.com;
    charset      utf-8;

    include /etc/nginx/default.d/*.conf;

    location / {
      include uwsgi_params;
      uwsgi_pass django;
    }

    location /static/ {
      alias /usr/local/etc/dmp/static/;
    }
}

和uwsgi设置

[uwsgi]

chdir = /usr/local/etc/dmp

module = DMP_python.wsgi

plugins = python3

socket = :8000

chmod-socket = 666

master = true

processes = 2

vacuum = true
python django nginx centos7 uwsgi
2个回答
0
投票

您使用错误的设置告诉uwsgi使用HTTP端口。你需要http-socket而不是socket


0
投票

可能有多种原因导致上游无效或甚至不返回任何响应

  • 验证上游uwsgi是否实际在centos实例中本地运行,并且可以处理传入的请求 为此验证在uwsgi.ini中运行它为http-socket = :8000然后运行uwsgi --ini uwsgi.ini 如果uwsgi在localhost上正常运行,那么将配置更改回socket = :8000
  • 在centos 7.x上启用SELinux包并以强制模式运行。因此它不允许nginx写入/连接到套接字。 验证SELinux是否具有nginx写入套接字的策略 检查是否允许读取/连接/写入套接字grep nginx /var/log/audit/audit.log | audit2allow -m nginxgrep nginx /var/log/audit/audit.log | audit2allow -M nginx这样做 最后semodule -i nginx.pp 现在应该解决连接套接字问题的权限 验证nginx是否可以与上游建立网络连接。检查nginx error.log或getsebool -a | grep httpd 允许它运行setsebool httpd_can_network_connect on -P
© www.soinside.com 2019 - 2024. All rights reserved.