Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

5 Answers

up vote 2 down vote accepted

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)

share|improve this answer
    
To make sure the old webserver is updated on the new DNS. Add the record to /etc/hosts. –  Matthew Scragg Jul 9 at 16:35
add comment

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.

share|improve this answer
add comment

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  me@domain.com
  ServerName domain.com
  DocumentRoot /var/www/

  ProxyRequests Off

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  ProxyPass / http://domain.com/
  ProxyPassReverse / http://domain.com/
</VirtualHost>

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

1.2.3.4 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
share|improve this answer
    
Nice. How to handle arbitrary subdomains, though? –  Ekevoo Aug 1 '12 at 10:22
add comment

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.

share|improve this answer
add comment

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
<VirtualHost 1.1.1.1:80>
    ServerName www.domain.com
    RewriteEngine on
    RewriteRule ^(.*)$ http://www-new.domain.com$1 [L]
</VirtualHost>

# new server
<VirtualHost 1.1.1.2:80>
    ServerName www.domain.com
    ServerAlias www-new.domain.com
</VirtualHost>

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
<VirtualHost 1.1.1.1:80>
   ServerName www-new.domain.com
   RewriteEngine on
   RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L]
</VirtualHost>

# new server
<VirtualHost 1.1.1.2:80>
    ServerName www.domain.com
    # ServerAlias removed, no longer needed
</VirtualHost>

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.

share|improve this answer
add comment

protected by voretaq7 Dec 3 '12 at 16:42

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.