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: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04
Then I tried to restructure the application following this tutorial: https://pythonise.com/series/learning-flask/flask-application-structure
I am getting a 502 bad gateway error.
my current folder structure is as follows:
sieroApp
|
|
|-sieroApp
| |
| |-- __init__.py
| |__ views.py
|
|-sieroApp.ini
|-sieroAppenv
|-wsgi.py
content of files: init.py:
from flask import Flask
app = Flask(__name__)
from app import views
content of views.py:
from app import app
@app.route("/")
def index():
return "Hello world"
@app.route("/about")
def about():
return "All about Flask"
content of sieroApp.ini:
[uwsgi]
module = wsgi:app
master = true
processes = 5
socket = sieroApp.sock
chmod-socket = 660
vacuum = true
die-on-term = true
content of wsgi.py:
from sieroApp import app
if __name__ == "__main__":
app.run()
content of etc/systemd/system/sieroApp.service:
[Unit]
Description=uWSGI instance to serve sieroApp
After=network.target
[Service]
User=max
Group=www-data
WorkingDirectory=/home/max/sieroApp/sieroApp
Environment="PATH=/home/max/sieroApp/sieroAppenv/bin"
ExecStart=/home/max/sieroApp/sieroAppenv/bin/uwsgi --ini sieroApp.ini
[Install]
WantedBy=multi-user.target
```
content of etc/nginx/sites-available/sieroApp:
```nginx
server {
listen 80;
server_name pixelbots.net www.pixelbots.net;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/max/sieroApp/sieroApp/sieroApp.sock;
}
}
```
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!
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!
Regards, KFSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.