txacme icon indicating copy to clipboard operation
txacme copied to clipboard

Add an introductory tutorial

Open Julian opened this issue 8 years ago • 1 comments

Hi!

I think it might be useful to have a tutorial which covers "here are the steps you should take as someone who wants to set up a website with HTTPS on a new (sub)domain using txacme".

E.g., I am passingly familiar with letsencrypt, and with the letsencrypt binary, having used them a total of one time before discovering txacme. I'm also familiar with twisted.web, and specifically with endpoints. What I was missing though was a way to connect the dots. Sample outline, just based on the steps you just told me to perform:

  • Install txacme
  • Create a directory for certs, and touch an empty file to signal txacme to renew the corresponding cert
  • Edit DNS settings to add a record for that domain to allow auth
  • Run txacme

(This is awesome by the way, looks like I'm quite close, once I remember my router password. Sigh.)

Julian avatar Jun 11 '16 15:06 Julian

Here some code to get things running with Flask:

import os
import sys

from flask import Flask
from twisted.internet import reactor
from twisted.web.wsgi import WSGIResource
from twisted.web.server import Site
from twisted.internet.endpoints import serverFromString
from twisted.python import log

app = Flask(__name__)

log.startLogging(sys.stdout)
wsgi = WSGIResource(reactor, reactor.getThreadPool(), app)
site = Site(wsgi)

# http
endpoint = serverFromString(reactor, "tcp:80")
endpoint.listen(site)

# https
try:
    os.mkdir("_certs")
except OSError:
    pass
pem_path = os.path.join("_certs", "mysubdomain.duckdns.org.pem")
if not os.path.exists(pem_path):
    open(pem_path, "wb").close()
endpoint = serverFromString(reactor, "le:_certs:tcp:443")
endpoint.listen(site)

reactor.run()

lazka avatar Oct 22 '17 14:10 lazka