SABIO's backend is a Python Flask
application that uses NGINX
as reverse-proxy and Gunicorn
as WSGI HTTP server. It has been developed on a Ubuntu 20.04.3 LTS
server.
Requirements, installation instructions and configuration files can be found in this directory.
OS install (self-standing applications; used Ubuntu's apt
package manager):
nginx
certbot
(sets up certificates for HTTPS, incl redirect in the NGINX config; followed thecertbot
installation instructions for NGINX + Ubuntu 20) -- NB: certbot requires the HTTP server to be already installed and configured (as it needs to change that configuration))
Python install (used Python's pip3
):
gunicorn
flask
pipenv
- other required Python packages -> see requirements.txt
Need to create a virtual environment in the directory /var/www/flask/sabio/
(with python -m venv /var/www/flask/sabio/
)
-
flask.service
: defines a service for the Flask app (actually for Gunicorn, which is responsible for starting Python workers),
located in/lib/systemd/system/
, service can then be started/monitored/stopped with(sudo) systemctl start/status/stop flask
-
nginx.service
: defines a service for the NGINX reverse-proxy server, located in/lib/systemd/system/
,
service can then be started/monitored/stopped with(sudo) systemctl start/status/stop nginx
, this file is
automatically created when installing NGINX (not manually modified) -
reverse-proxy.conf
: the config file for the NGINX reverse-proxy server, located in/etc/nginx/sites-enabled/
-
start.sh
: executed byflask.service
(this bash script actually runsgunicorn
), located in/var/www/flask/sabio/
, activates the Python virtual environment and runsgunicorn
with the Python scriptapp.py
and appropriate parameters
list of Flask/Gunicorn/Nginx setup tutorials that were followed to create the SABIO backend; needed to diverge from their instructions a number of times but they might still be helpful references (and explain some configurations in more detail):
-
instructions on deploying a Flask app with Gunicorn and NGINX; mainly followed this one
-
DigitalOcean: how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04
-
Nginx tutorial that could help figure out how to set an internal redirect from / to /api/v0
-
NGINX Config Pitfalls -- a list of problems and bad practices