I was considering switching to Amazon EC2 to host my website to handle more traffic. It seems like I would have to update DNS records to point to the new server but I was wondering if there was a way to avoid having to wait for the new DNS record to propagate. Putting the code on both hosts would not work for me since the app writes to a database pretty frequently. I thought about just using a meta redirect or php redirect on the old host to redirect to the new host ip but was wondering if there's a better more accepted way of doing this.


4 Answers 4


here is a trick i use all the time... :) it assumes you control the current server.

put the site/db/whatever on the new server and on your old/current server, enable the proxy, proxy_http and the rewrite modules, then add the following lines on the apache config file for your old/current site:

RewriteEngine on
ProxyPass          /      http://<your-fqdn-here>/
ProxyPassReverse   /      http://<your-fqdn-here>/

lastly, add an entry on your the /etc/hosts file of your old/current server that has the following syntax:

<new-ip-address-of-ec2>   <your-fqdn-here>

that is it. you got a reverse proxy pointing to itself, but resolving its own name to your new server. when the dns propagation rolls out, then the new server will be hit directly. we call this neat little trick PRRP or Pseudo-Recursive-Reverse-Proxy.

For those pesky (by pesky I mean badly designed) web apps that require many holes poked on the firewall, this lets you leave just the reverse proxy server on the dmz and poke only ports 80/443 to the internal network.

  • +1 But just to clarify by apps that requires many holes poked on the firewall I think you mean webapps behind the firewall using nonstandard ports or running on their own host. Commented Apr 2, 2010 at 23:33
  • @alexandre - yes, webapps! the generalization was force of habit.. been doing [mainly] webapps for a while. :) I updated my post to reflect your correction. Commented Apr 2, 2010 at 23:47

Have your old host proxy the http requests to the new host


You might also be able to reduce the time you have to wait for the DNS propagation by getting the TTL for the domain name lowered preparatory to the move.

  • Wow, I just created this account in the last few minutes and already I've got 31 points...
    – SamB
    Commented Apr 28, 2010 at 0:20

(This improves on the answer by Peter Carrero here, by avoiding the need for local DNS bending.)

  1. Install the website on your new server.

  2. On your old server, enable some Apache modules first:

    a2enmod proxy
    a2enmod proxy_http
    a2enmod rewrite
  3. Add to the vhost config of your website on the old server (where 123.456.1.1 represents the IP address of your new server):

    RewriteEngine     on
    RewriteCond       %{HTTPS} off
    RewriteRule       (.*)  https://%{HTTP_HOST}%{REQUEST_URI}
    ProxyPreserveHost on
    ProxyPass         /     http://123.456.1.1/
    ProxyPassReverse  /     http://123.456.1.1/
  4. Make sure you do not have any forwarding from HTTP to HTTPS traffic configured for your website on your new server. In combination with the proxy configuration, it would result in a redirect loop.

  5. After DNS propagation is over, remove the vhost config of your website from the old server, but move the part for HTTP to HTTPS redirection of it to the new server (if desired).

Explanation: Like with Peter's answer, we get a reverse proxy pointing to the same website on a different server. But rather than DNS bending via /etc/hosts, we create the same effect of overwriting DNS purely within the Apache config with ProxyPreserveHost on. According to the Apache manual, this will keep the Host: HTTP header of the original, incoming request set when proxying it to the new server. So the server will use it as normally for name-based virtual hosting.

You must log in to answer this question.

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