Installing a certificate with flask app - jordy33/turbogears_tutorial GitHub Wiki
Step 1. Install the following in ubuntu 16.04
sudo apt-get update
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot
Step 2. Stop all services in port 80 or 443 and create certificate
sudo certbot certonly --standalone -d instala.dwim.mx
cd /etc/letsencrypt/live/instala.dwim.mx
Step 3. Go inside your flask Directory and create certs directory
mkdir certs
cd certs
cp /etc/letsencrypt/live/instala.dwim.mx/cert.pem .
cp /etc/letsencrypt/live/instala.dwim.mx/privkey.pem .
Modify the tornado configuration:
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from manage import app
import os
basedir = os.path.abspath(os.path.dirname(__file__))
app.debug = False
#print(basedir)
http_server = HTTPServer(WSGIContainer(app))
http_server = HTTPServer(WSGIContainer(app), ssl_options={
"certfile": os.path.join(basedir+"/certs/", "cert.pem"),
"keyfile": os.path.join(basedir+"/certs/", "privkey.pem"),
})
#http_server.listen(80)
http_server.listen(443)
IOLoop.instance().start()