Python Django+Nginx+uwsgi 502 错误网关
Python Django+Nginx+uwsgi 502 Bad Gateway
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
您使用了错误的设置来告诉 uwsgi 使用 HTTP 端口。你需要 http-socket
而不是 socket
.
可能有多种原因导致上游 return 无效甚至不 return 任何响应
验证上游 uwsgi 是否确实 运行在 centos 实例中本地运行并且可以处理传入请求
为此要验证 运行 它是 uwsgi.ini 中的 http-socket = :8000
然后 运行 uwsgi --ini uwsgi.ini
如果 uwsgi 运行在本地主机上运行良好,则将配置更改回 socket = :8000
在 centos 上 7.x SELinux 软件包已启用并且 运行s 处于强制模式。所以它不允许 nginx write/connect 到套接字。
- 验证 SELinux 是否有 nginx 写入套接字的策略
- 检查是否允许 read/connect/write 到套接字
grep nginx /var/log/audit/audit.log | audit2allow -m nginx
grep 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
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
您使用了错误的设置来告诉 uwsgi 使用 HTTP 端口。你需要 http-socket
而不是 socket
.
可能有多种原因导致上游 return 无效甚至不 return 任何响应
验证上游 uwsgi 是否确实 运行在 centos 实例中本地运行并且可以处理传入请求
为此要验证 运行 它是 uwsgi.ini 中的
http-socket = :8000
然后 运行uwsgi --ini uwsgi.ini
如果 uwsgi 运行在本地主机上运行良好,则将配置更改回
socket = :8000
在 centos 上 7.x SELinux 软件包已启用并且 运行s 处于强制模式。所以它不允许 nginx write/connect 到套接字。
- 验证 SELinux 是否有 nginx 写入套接字的策略
- 检查是否允许 read/connect/write 到套接字
grep nginx /var/log/audit/audit.log | audit2allow -m nginx
grep 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