I currently have a domain name registered for a Linux/Apache server that I am going to replace with another on a new IP address.

Migrating the data will be relatively quick and a 5 minute disruption during that process is acceptable.

The DNS record has a TTL from 6-12 hours apparently, which I can't speed up.

What are the likely consequences of this change? Presumably users who are still looking at the old address will continue to hit the old server, while users who's dns cache has expired or is empty will see the new domain.

Is it possible to do some kind of redirect from the old server (with Apache or iptables) to the new IP? The old server can continue to run as long as necessary.

  • I used rinetd which is more general than a particular vhost, but works brilliantly if you're replacing the entire server, or, say, moving all web stuff to another server. Just sync the new server, set up rinetd, change DNS. In 48 hrs turn off old server (or its services). Commented Feb 12, 2015 at 14:05

5 Answers 5


You can use a Reverse Proxy on the old web server. It might be a bit of work to set up, but just as long as ITS DNS is up to date you will be OK.

What will happen is:

  1. Old web server is configured to be Reverse Proxy
  2. DNS Switchover
  3. New web server serves hits from up-to-date DNS records
  4. Old web when it gets a hit, forwards the request to the correct DNS, and then outputs the content verbatim.

If you're running Apache, look into mod_proxy. If you're running IIS, look into ISAPI Rewrite to get this sort of functionality.

(note that the DNS on the old web server needs to be up to date if you want to proxy using the domain name. Otherwise, proxy it directly to the IP address and make sure that the host is listening on the IP without a hostname)

  • 1
    To make sure the old webserver is updated on the new DNS. Add the record to /etc/hosts. Commented Jul 9, 2014 at 16:35
  • @MatthewScragg Can you give some more information regarding that? Steps and results..
    – Birla
    Commented Jul 15, 2014 at 13:20
  • 1
    @Birla On the old webserver, add to /etc/hosts 123.456.789.12 my.domain.com This will only let your old web server know of the updated address. When a client accesses the old webserver (because they don't have updated DNS) the webserver can proxy the request using the domain name. I don't use Apache but here is a Nginx example: gist.github.com/scragg0x/738f144b33d17ef763d1 Commented Jul 15, 2014 at 14:40

My company just did this with several largish Web sites. The basic procedure we followed was:

  1. Lower the domain's TTL as much as possible. Do this in advance by at least as much time as the current TTL.
  2. Set up the Web site on the new server exactly how you want the "final product" to be
  3. Add an aliased name to the site on the new server, such as www2.domain.com or www-new.domain.com. With Apache, you would use the ServerAlias directive. If the site has any dynamic code at all (PHP, mod_perl, RubyOnRails, etc.), make certain that the site will behave and respond correctly with this new name.
  4. At cutover time, set up a redirect on the old server pointing to the new server
  5. Change DNS for www to go to the new IP.

For Apache, you should probably use mod_rewrite for the redirect so you can preserve the URIs requested by the client. A simple implementation would be:

# old server
    ServerName www.domain.com
    RewriteEngine on
    RewriteRule ^(.*)$ http://www-new.domain.com$1 [L]

# new server
    ServerName www.domain.com
    ServerAlias www-new.domain.com

This will do a 302 temporary redirect for www.domain.com/anything to www-new.domain.com/anything. You want it to be temporary because you probably want search engines to only index www.domain.com, not www-new.domain.com.

Once the DNS change for www.domain.com has propagated to your satisfaction, you can either dump www-new altogether, or gently ease anyone using it back over to www with another redirect. It's almost the same process as above; set up the old server to handle www-new, change DNS for www-new to point to the old server, and set up a redirect on the old server sending www-new traffic to www:

# old server
   ServerName www-new.domain.com
   RewriteEngine on
   RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L]

# new server
    ServerName www.domain.com
    # ServerAlias removed, no longer needed

This time you want to do a permanent 301 redirect, again to clue in search engine crawlers that www.domain.com is the site you want them to index.


Ok, based on what @Farseeker recommended, I set up the following config on the old Apache server to forward requests onto the new server:

<VirtualHost *>
  UseCanonicalName Off
  ServerAdmin  [email protected]
  ServerName domain.com
  DocumentRoot /var/www/

  ProxyRequests Off

  <Proxy *>
    Order deny,allow
    Allow from all

  ProxyPass / http://domain.com/
  ProxyPassReverse / http://domain.com/

To make sure the old server had the correct address, I put an entry in /etc/hosts: domain.com

I also had to enable the Apache mod_proxy and mod_proxy_http modules, and reload the config:

a2enmod proxy
a2enmod proxy_http
/etc/init.d/apache force-reload
  • Nice. How to handle arbitrary subdomains, though?
    – Liz
    Commented Aug 1, 2012 at 10:22

It's an old thread but maybe it will help someone:

In addition to answers of Mark Henderson (mod_proxy) OR James Sneeringer (302,301 redirect to new subdomains), one more thing could be added regarding database sync when moving big applications.

If your web project uses a database (ex. MySQL), before switching the DNS, make sure the applications (ex. PHP) from both servers are connecting to the same database. So that the read and writes are going to the same place and you don't have to deal with different DB sync tools afterward.

This would (most probably) affect the loading time on one server but for the switch period this can be accepted.

In case the DB server is not accessible from outside, you could setup also the mysql_proxy on the web server which has access to it and is accessible from external IPs.


I use iptables for this when I need to do this; a quick bit of DNAT/SNAT and all your traffic magically reappears where it should be. If you have a real need to maintain source IP addresses a reverse proxy can help, by setting appropriate headers, but that requires a lot of faffing around at both ends to make sure it all matches up, so I don't normally worry about it for something like a migration as it's transient, and lowering TTLs handles most of it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .