Moving a website to a new server without downtime
migrationdnsttlcertbotlets-encryptreverse-proxyapachenginxold-server
Moving a site from an old server to a new one has an awkward middle period: the new server is ready but DNS still points at the old one, and DNS changes take up to a full TTL to reach everyone. The trick is to make the old server forward to the new one during that window, so it does not matter which address a visitor's resolver has cached. The same forwarding lets the new server get its TLS certificate before DNS moves. Worked example: justinandrewhampton.com, moved from the CentOS 7 old server (45.79.19.71) to the Alma 9 server (45.79.9.71) on 2026-10-22.
Steps
- Inventory and audit the old site before copying it. Copy the docroot into a git repo, then read every executable file. Drop whatever is not needed: a static page with an empty PHP block can become plain HTML and stop needing PHP at all.
- Do not carry over secrets or dangerous endpoints. The jah site's
ajax.phpwas an unauthenticated contact-form mailer (anyone could send mail through it) with a Gmail SMTP password hardcoded in the source. It was left behind, made unreachable, and the owner was told to rotate that password. Old PHP sites often hold credentials in plain files; grep forpassword,smtp,mysqlbefore deploying anything. - Set up the site on the new server: docroot, Apache vhost on :8008, nginx server block (see
nginx in front of Apache (TLS proxy on :8008)),
restoreconon the files (SELinux file contexts and booleans on web servers). Test it before DNS moves withcurl --resolve example.com:443:<new-ip> https://example.com/(or:80:before there is a cert). - Get the certificate early by forwarding ACME challenges. In the old server's port-80 vhost,
proxy
/.well-known/acme-challenge/to the new server. Let's Encrypt validates against the old IP, the request lands on the new server, andcertbot --nginx -d example.comsucceeds there while DNS still points at the old box. - Make the old server a reverse proxy. In the old HTTPS vhost, replace the site with a
proxy to the new server:
SSLProxyEngine on,ProxyPreserveHost On,ProxyPass / https://<new-ip>/(certificate verification off, since the cert's name won't match the IP). Now visitors on either address see the new site. Back up both old vhost files first. - Flip the A record in the DNS manager. With a TTL of 86400 the switch trickles in over 24
hours; nobody sees an outage because the old server keeps forwarding. Check progress with
dig @1.1.1.1 example.com. - After a full TTL, the old-server edits are irrelevant. The old cert there can lapse.
Gotchas
- Only request names that resolve. justinandrewhampton.com had no
wwwrecord, so the cert covers the apex only. Asking certbot for a name with no DNS fails the whole request. - The proxy hop keeps the old server in the request path until DNS moves: if it is being shut down, the flip has to happen first.
- DNS edits may need a human: with no DNS provider API token on the desktop, the A-record change was handed to Justin. Say exactly which record changes from what to what, and the TTL.
deploy.shfor the moved site should check the new server explicitly (curl --resolve), not the public name, or it will happily verify the old server during the transition.
See also
- Responding to a critical PHP security release (and what to do with an unpatchable server)
- Setting up an Alma Linux 9 LAMP server
- Deploy scripts with rsync (patterns and traps)
- nginx in front of Apache (TLS proxy on :8008)