Python Django+nginx+uwsgi 502 Bad Gateway
Centos7,when I connect to my website, shows 502 Bad Gateway, I test my website with command uwsgi --ini systemctl start nginx And I cant figure out what's happened,please help me!
Solution 1:
You're using the wrong setting to tell uwsgi to use an HTTP port. You need http-socket
rather than socket
.
Solution 2:
There can be multiple reasons for which an upstream might return invalid or even do not return any response
Verify if upstream uwsgi is actually running locally in the centos instance and can handle incoming requests
for this to verify run it as
http-socket = :8000
in uwsgi.ini and then runuwsgi --ini uwsgi.ini
if uwsgi running fine on localhost, then change config back to
socket = :8000
On centos 7.x SELinux package is enabled and runs in enforcing mode. So it won't allow nginx to write/connect to a socket.
- verify if SELinux has the policy for nginx to write to sockets
- check if read/connect/write to socket is allowed
grep nginx /var/log/audit/audit.log | audit2allow -m nginx
- do so by
grep nginx /var/log/audit/audit.log | audit2allow -M nginx
- and finally
semodule -i nginx.pp
- permission to connect to socket issue should be resolved by now
- verify if nginx can do network connection with upstream. Check nginx error.log or
getsebool -a | grep httpd
- to allow it run
setsebool httpd_can_network_connect on -P
Post a Comment for "Python Django+nginx+uwsgi 502 Bad Gateway"