I ended up putting together a couple of Caddyfiles for the Caddy server. The project really wants users to choose automatic HTTPS, but it wasn’t a good fit for using with a load balancer and auto-scaling. Surprisingly, it is willing to contact the production Let’s Encrypt API even without an email address.
Anyway, I have a few pieces here to cover:
- The easiest way to ignore HTTPS, and returning a fixed error message on HTTP
- Mysterious error messages, relating to the way Caddy chooses certificates and configuration blocks
- Using the tls directive to get self-signed certificates for a public name, for using HTTPS between Caddy and a load balancer which does not validate certificates
- How to use trusted_proxies—and a bit more trickery—so that, using HTTP behind a load balancer, PHP knows the client’s connection is HTTPS
- How to compose multiple URL mappings, and using a front controller for PHP apps
Aside from the above links, Caddy provides more conceptual documentation at the Automatic HTTPS article.
My end goal is to get FrankenPHP running, but as it is built on Caddy, I wanted to understand that part before moving ahead.