Skip to content

Instantly share code, notes, and snippets.

@ruggeri
Created April 2, 2018 04:34
Show Gist options
  • Save ruggeri/27e8f043d4ea575077beca0f9cc01551 to your computer and use it in GitHub Desktop.
Save ruggeri/27e8f043d4ea575077beca0f9cc01551 to your computer and use it in GitHub Desktop.

Ubuntu instructions (https://certbot.eff.org/lets-encrypt/ubuntutrusty-other) summary:

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install certbot
sudo certbot certonly

Use the temporary server version.

NOTE: In EC2 security groups make sure to add HTTPS (port 443) open on inbound. You should already have port 80 open.

from flask import Flask
import ssl

app = Flask(__name__)

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain(
    # Use your own domain name of course
    certfile = '/etc/letsencrypt/live/blog.self-loop.com/cert.pem',
    keyfile = '/etc/letsencrypt/live/blog.self-loop.com/privkey.pem',
)

@app.route("/")
def hello():
    return "Hello World!"

app.run(
    # Get your own hostname by typing `hostname` in the command line.
    host = 'ip-172-31-4-252',
    # You probably need to set the port explicitly.
    port = 443,
    ssl_context = context
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment