bad gateway flask nginx uwsgi

Posted April 12, 2021 314 views

I’m trying to expand from a basic one file flask app and restructure into a proper application. I followed and initial set up on a digital ocean server from a tutorial I found here:

Then I tried to restructure the application following this tutorial:

I am getting a 502 bad gateway error.

my current folder structure is as follows:

       |      |
       |      |--
       |      |__

content of files:

from flask import Flask
app = Flask(__name__)

from app import views
content of

from app import app

def index():
    return "Hello world"

def about():
    return "All about Flask"

content of sieroApp.ini:

module = wsgi:app

master = true
processes = 5

socket = sieroApp.sock
chmod-socket = 660
vacuum = true

die-on-term = true

content of

from sieroApp import app

if __name__ == "__main__":

content of etc/systemd/system/sieroApp.service:

Description=uWSGI instance to serve sieroApp

ExecStart=/home/max/sieroApp/sieroAppenv/bin/uwsgi --ini sieroApp.ini


content of etc/nginx/sites-available/sieroApp:

    server {
        listen 80;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/max/sieroApp/sieroApp/sieroApp.sock;
edited by MattIPv4

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.

Submit an Answer
1 answer

Hi @eventhorizon02,

I can’t see any issues with the files you’ve provided. Having said that, the issue might be somewhere else, what does your Nginx error_log say?

Usually, when you are not sure what exactly the error is and you are seeing something generic like 502 Bad Gateway, the best option is always to go and check the the service’s error log. Regarding Nginx, you should be able to see the log at /var/log/.

Please check it there and see if you can further troubleshoot your application. If you are not sure how to continue, post the error here and we’ll try to help out!