Last month, a WordPress site with a fairly active forum (related to Beatles) needed to be migrated to another server. The forum had a new post at least every 30 minutes, including on week ends when the traffic to the site is the lowest.
This is the rough overview of the process:
- Lowered the TTL of the domain (and sub-domains) to 300 seconds 1
- Set up the new server
- Took a backup of the WordPress site and migrated it to the new server
- Tested the site thoroughly in the new hosting environment
- Took another backup of the site and migrated to the new host 2
- Put the forum in read-only mode in the origin server
- Updated the DNS to point to the new host
- Waited patiently for the traffic in the new server
We thought we did everything right. However, while we could see the increased traffic to the new server, we were amazed at the number of users who kept coming back to the old host, even after 48 hours, irrespective of the lower TTL.
We did many things incorrectly!
What if the forum doesn’t have a read-only mode?
What if the forum had a traffic spike during the migration?
What if the forum lost all those visitors who happened to see only the read-only mode for over 48 hours?
Recently, I watched a video by Mark Jaquith who mentioned this exact scenario. Only at the time of watching, a clever idea came up from nowhere that could have prevented most of the IFs mentioned above.
The trick is to use the reverse proxy in the old host. Let me explain. If you are in a similar situation, just after switching the DNS, edit your site’s vhost entry to have the following reverse proxy configuration…
server {
listen 80;
server_name domainname.com www.domainname.com;
access_log "/var/log/nginx/domainname.com-migration.log";
location / {
# replace ip.ip.ip.ip with the actual IP of the new server
proxy_pass http://ip.ip.ip.ip;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Can’t get simpler than this! So, when someone visits the old server, all those requests are reverse-proxied to the new server.
No need to turn-on the read-only mode.
No need to worry about traffic spike.
No loss of regular visitors (new visitors would see the new IP anyway).
The same configuration can be modified to other web servers as well, such as Apache. However, Apache doesn’t offer a way to do this via htaccess file. One needs to edit the vhost entry to apply this change. So, this method can’t be used on a shared host, running Apache web server.
Happy hosting!