Skip to content Skip to sidebar Skip to footer

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

    1. for this to verify run it as http-socket = :8000 in uwsgi.ini and then run uwsgi --ini uwsgi.ini

    2. 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.

    1. verify if SELinux has the policy for nginx to write to sockets
    2. check if read/connect/write to socket is allowed grep nginx /var/log/audit/audit.log | audit2allow -m nginx
    3. do so by grep nginx /var/log/audit/audit.log | audit2allow -M nginx
    4. and finally semodule -i nginx.pp
    5. permission to connect to socket issue should be resolved by now
    6. verify if nginx can do network connection with upstream. Check nginx error.log or getsebool -a | grep httpd
    7. to allow it run setsebool httpd_can_network_connect on -P

Post a Comment for "Python Django+nginx+uwsgi 502 Bad Gateway"