Bad Gateway 502 error - Nginx Flask Python Confirguration

I am attempting to configure Nginx to run my flask/python application on a Linux Centos 7 server. I am getting a Bad Gateway 502 error. I am new to using Nginx so I am hoping I am going the right direction. Here are my files. Error message [error] 91680#0: *23 connect() to unix:/var/www/MyApp/MyApp.sock failed (111: Connection refused) while connecting to upstream, client:, server: _, request: “GET /favicon.ico HTTP/1.1”, upstream: “uwsgi://unix:/var/www/MyApp/MyApp.sock:”, host: “”, referrer: “http://ip.address/MyApp/


[uwsgi] module = wsgi

master = true processes = 5


[uwsgi] module = wsgi

master = true processes = 5

socket = MyApp.sock chmod-socket = 664 vacuum = true

die-on-term = true


server { listen 8000; server_name;

location / { include uwsgi_params; uwsgi_pass unix:/var/www/MyApp/MyApp.sock; } }

server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /var/www/MyApp; }

location / { uwsgi_pass unix:/var/www/myapp/MyApp/MyApp.sock; uwsgi_param UWSGI_TOUCH_RELOAD /var/www/MyApp/MyApp.sock; include uwsgi_params;

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This error means that nginx is unable to connect to uWSGI through the socket. This can happen in one of two cases:

  1. uWSGI isn’t running
  2. the socket path is not correct

Your config files looks fine, so I’m guessing it’s 1. Is uWSGI running? You can check by running this command and seeing if it outputs anything:

sudo ps wwaux | grep -i uwsgi