Moving a domain to a new server without a certificate gap
Migrating an app to a new server usually goes like this: deploy on the new server, switch DNS, wait for a certificate. During that wait, some visitors reach the new server and get a certificate warning. You can avoid the gap.
Why it happens
The default Let's Encrypt HTTP challenge needs the domain to already point at the new server. Until DNS changes, the new server cannot get a certificate. After DNS changes, the first visitors arrive before the certificate is issued.
Option 1: DNS challenge
If your proxy supports the DNS-01 challenge with your DNS provider, the new server can obtain the certificate before any traffic arrives. Give it an API token scoped to the one zone. Once the certificate is in place, switch the record.
Option 2: copy the certificate
Copy the current certificate and key from the old server to the new one and configure the proxy to use them until its own certificate is issued. Keep file permissions tight and delete the copy afterwards.
Option 3: forward the challenge
On the old server, proxy requests for /.well-known/acme-challenge/ to the new server. The new server can then complete the HTTP challenge while DNS still points at the old one.
Lower the TTL first
A day before the move, drop the record's TTL to 300 seconds. The switch then propagates in minutes.
Verify before switching
curl -sI --resolve app.example.com:443:NEW_IP https://app.example.com | head -1
A 200 with no certificate error means you are ready.
Keep the old server up
Leave it running until traffic on it stops.
The Peon docs on custom domains and automatic SSL show how domains are attached to services. I work on Peon, an open-source self-hosted deployment platform.