Skip to content

HTTPS and Certificates

The outcome of this chapter is a proxy host with a padlock: a certificate from Let's Encrypt attached to it, visitors forced onto HTTPS, and renewals that happen without you. Read the honesty label first, because this chapter is different from the last three: the lab could not run a real certificate request. Issuance needs a public name that resolves to the machine and a port 80 the internet can reach — a sandbox has neither, and the Certbot program itself was not present there (transcript t12). What the lab did verify is everything around the request: the certificate machinery is part of the same backend (chapter 2), its renewal timer starts with the program and logs its rounds (transcript t04), certificates are first-class records in the API (transcript t11 returned the lab's — empty — list), and the generated configuration's certificate-shaped pieces are the ones chapters 6 read. The request flow below is taught from the project's documentation, and criteria.md files it as documented-only.

The idea. A certificate binds a name to a key, signed by an authority browsers trust. Let's Encrypt gives them away, but only to whoever proves they control the name. NPM offers Certbot two ways to prove it:

  • HTTP challenge — the default. Certbot plants a temporary file; NPM serves it from a temporary nginx configuration (the backend generates a letsencrypt_<id>.conf for exactly this); Let's Encrypt fetches http://<your-name>/.well-known/acme-challenge/… from the public internet. Your name must resolve to this machine and port 80 must be open to the world.
  • DNS challenge — for names that must not be reachable publicly (an internal-only service), or for wildcard certificates (*.example.com). You pick your DNS provider from NPM's long plugin list and give it an API token; Certbot proves control by writing a TXT record instead. The token is a credential with write access to your DNS — chapter 1's credential care applies in full, and a token scoped to one zone beats your master DNS login.

The procedure. Open the proxy host, go to its SSL tab: Request a new SSL Certificate. Tick Force SSL (visitors arriving on HTTP are redirected to HTTPS) and HTTP/2 Support; HSTS adds the strict-transport promise from chapter 6's map block — enable it once you are sure HTTPS is staying, because browsers remember it and will refuse plain HTTP for the name afterwards. Agree to the Let's Encrypt terms and save. On success the host's file is regenerated with listen 443 ssl, certificate paths under /etc/letsencrypt/live/…, and the force-SSL include — the same generation machinery, with more of its switches on.

Renewals are the design, not a chore. Let's Encrypt certificates live 90 days. The backend runs a renewal timer — the lab's startup log shows it initialising and completing a round with nothing to do (transcript t04) — and renews certificates expiring within 30 days. Your job reduces to noticing if it ever fails, which the interface shows on the SSL Certificates page.

The check: for a host you have secured, curl -sI https://app.example.com should answer from your service, over TLS, and curl -sI http://app.example.com should answer a redirect to the https address. In the interface, the certificate's expiry date should sit comfortably in the future — and stay there, month after month, without you touching it.