This repository contains necessary files and configs to build Nginx + Gunicorn + Flask with Letsencrypt using Docker and docker-compose.
Note: Tested on Ubuntu 16.04 and 18.04
+---------------------------------------+
| service | image | version |
+====================|========|=========+
| Flask and Gunicorn | alpine | 3.7 |
+--------------------|--------|---------+
| Nginx | nginx | latest |
+---------------------------------------+
- docker - install cmds for ubuntu 16.04 or 18.04
- docker-compose - install cmds for ubuntu 16.04 or 18.04
- make -
sudo apt install make
- a domain name linked to your server
In the .env
file, enter your application details for the below variables.
SSL_EMAIL=myemail@myemail.com
NGX_DOMAIN=mysuperwebsite.com
FLASK_SESSION_KEY=super_secret_key
FLASK_ENV=development
*SSL_EMAIL: Email address for Letsencrypt SSL certificate
*NGX_DOMAIN: Domain name for Nginx config and Letsencrypt SSL certificate
*FLASK_SESSION_KEY: Secret Key for Flask Session. It can be whatever you want. ie. 6d8dg8f4-49f493bf9-h30f489h9n
*FLASK_ENV: Python application environment development / production.
We need to install the Letsencrypt client to get the SSL certicates.
$ make install-le-client
You might need to enter your sudo password as the command needs to run with admin privileges.
It installs the Letsencrypt client and get a certificate for the specified domain name and email address.
Wait for the installation and follow the different instructions.
Note: Free Letsencrypt cert are only available for 90 days. To renew the cert run
$ make renew-le-cert
Start application
$ sudo make dc-start
Your web app should be now accessible at your domain with SSL certificates 🎉
Stop application
$ sudo make dc-stop