How can I get SSL for a Flask app run over Gunicorn?

Viewed 4248

I run a Flask app over Gunicorn on Ubuntu 18.04. Gunicorn runs on Port 80. I have NGINX setup, but it isn't used and is disabled. I was able to successfully setup cert-bot for NGINX, but it doesn't help as NGINX isn't used and it also conflicts with gunicorn on Port 80. Is it possible to get a SSL Certificate specifically for Gunicorn/Flask or something that can work with it? SSL and https is essential for the page.

2 Answers

You can use certbot generated SSL Certificates with Gunicorn:

  1. Follow certbot instructions for software "Other". Note the location where generated files are saved.
  2. Run Gunicorn and specify certificate and key paths using --keyfile and --certfile options. Example: gunicorn --keyfile /some/path/key.pem --certfile /some/path/cert.pem main:app
Related