How to exchange a webserver maintaining the same IP address: haproxy

Scenario: An obsolete server hosting a website must be put offline and a new one must take his IP address. You don’t want to change all of yours A records on DNS to put online your new website, just exchange the internal IP address of your local network.

Your provider can exchange the addresses to assign the old IP public address to the new internal IP but it takes his time. How to cover the time between the provider action and your new website online?

Haproxy is the answer.

This is the content of the /etc/haproxy/haproxy.cfg:

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
# redirect all traffic on :80 to another server
frontend  main *:80
    default_backend             app

backend app
    balance     roundrobin
    # where 192.168.x.x is the internal address of the new server
    server  app1 192.168.x.x:80 check

And then restart haproxy (e.g. on centos 6 service haproxy restart).

Before configuring haproxy remember to stop or reconfigure the service listening to the port 80. If for example you want to reconfigure apache you have to change Listen 80 into something like Listen 8081 in /etc/httpd/conf/httpd.conf (CentOS 6 systems), if you have varnish listening to the 80 you have to change the VARNISH_LISTEN_PORT parameter in  /etc/sysconfig/varnish.

Now all the traffic arriving to the old server on port 80 will be redirected to the new server via local network. When the provider will exchange the addresses you haven’t to change anything. Meanwhile, you can test all the production settings prior to the real internal IP exchange.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s