4

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.

10

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.

| improve this answer | |
  • +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. – Alex Jasmin Apr 2 '10 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. – Peter Carrero Apr 2 '10 at 23:47
4

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

| improve this answer | |
4

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.

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

(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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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