2019-09-03 - Progress
A few months ago I wrote about Let's Encrypt on clustered Apache web servers. This note describes how to use a similar trick for migrating a web site to a new server.
The situation
You have an existing web site, say www.botolph.cam.ac.uk
, which is
set up with good TLS security.
It has permanent redirects from http://…
to https://…
and from
bare botolph.cam.ac.uk
to www.botolph.cam.ac.uk
. Permanent
redirects are cached very aggressively by browsers, which take
"permanent" literally!
The web site has strict-transport-security with a long lifetime.
You want to migrate it to a new server.
The problem
If you want to avoid an outage, the new server must have similarly good TLS security, with a working certificate, before the DNS is changed from the old server to the new server.
But you can't easily get a Let's Encrypt certificate for a server until after the DNS is pointing at it.
A solution
As in my previous note, we can use the fact that Let's Encrypt will follow redirects, so we can provision a certificate on the new server before changing the DNS.
on the old server
In the http virtual hosts for all the sites that are being migrated
(both botolph.cam.ac.uk
and www.botolph.cam.ac.uk
in our example),
we need to add redirects like
Redirect /.well-known/acme-challenge/ \ http://{{newserver}}/.well-known/acme-challenge/
where {{newserver}}
is the new server's host name (or IP address).
This redirect needs to match more specifically than the existing
http
-> https
redirect, so that Let's Encrypt is sent to the new
server, while other requests are bounced to TLS.
on the new server
Run the ACME client to get a certificate for the web sites that are
migrating. The new server needs to serve ACME challenges for the web
site names botolph.cam.ac.uk
and www.botolph.cam.ac.uk
from the
{{newserver}}
default virtual host. This is straightforward with
the ACME client I use, dehydrated.
migrate
It should now be safe to update the DNS to move the web sites from the old server to the new one. To make sure, there are various tricks you can use to test the new server before updating the DNS [1] [2].