I’m migrating from nginx to Caddy and I noticed that Caddy has a few seconds of downtime on startup when it’s trying to generate the certificates. I want to avoid the downtime by loading existing certificates and letting Caddy generate new ones while still distributing the HTTP traffic to backend servers, but I’m unsure how to approach this. My first idea was to:
Add auto_https ignore_loaded_certs to global config
Run Caddy and let the certificates generate and upload it to S3 so it can be reused on the next run.
So far it managed to load the certificates and it runs well, but the certification renewal was not triggered - I guess this would make sense if there’s no need to do it yet, but I’d rather make 100% sure the process goes well once it’s deployed to production. Is there any way to force the certification renewal anyhow?
I can’t help with what you’re trying to do, but how about persisting the certificates between container restarts? You could mount persistent storage for the data folder or use something like Redis to store the certificates. That way the very first start might be a bit delayed, but subsequent restarts wouldn’t be.
If you’re using filesystem as the backing storage for Caddy, you’ll have to replicate the directory structure that Caddy generates to track the certificates. It also includes a metadata JSON file. Successful migration of the form you’re describing requires replicating both directory structure and the metadata JSON file.
Is there any guide how to do that? there is some data in that JSON that I’m not sure how should be generated -e.g. _uniqueIdentifier, url, the LetsEncrypt account, etc.
From my quick search, certbot doesn’t seem to store or expose the email address of the LE account on disk. I could be wrong. Nonetheless, Caddy directory structure is like this:
The default is used when no email address is used, which is convenient. Certbot stores the private key in JWK format, while Caddy stores it as PEM, so you’ll have to convert that. The default.json contains this structure:
How do you get the certificate ID though? I tried to use the ID from the Certbot directory structure and paste it at the end of the url from issuer_data, but I get a 404 - while the one from Caddy works fine.