Provision a free certificate and auto-configure HTTPS
Certbot rewrites the config to listen on 443 with the certificate, and adds an HTTP→HTTPS redirect for the existing server block.
bash
certbot --nginx -d api.example.com
Step 4
Verify auto-renewal actually works
bash
certbot renew --dry-run
Expected result
What success looks like
https://api.example.com reaches the Spring Boot app, http://api.example.com redirects to HTTPS automatically, and the certificate renews itself before it expires.
Lessons learned
Tip
The app itself never needs to know about TLS at all — it just serves plain HTTP on localhost, and Nginx handles encryption entirely at the edge.
Tip
X-Forwarded-Proto is what lets the app correctly detect the original request was HTTPS, even though Nginx talks to it over plain HTTP internally — without it, redirect logic and secure-cookie logic in the app can misbehave.
Tip
Certbot's renewal is a scheduled job (cron or systemd timer) installed automatically — the dry-run is how you confirm it'll actually fire before you find out the hard way at 2am when a cert expires.