Fixing DNS problems while migrating ecommerce sites (e.g. Shopware or Magento)

Back in the days, when we migrated websites from one machine to another it was easy, get HTML and CSS, move it to another machine, change the DNS record and bam. Done.

Today it is not that easy, because we have a lot of services involved: CDN, DNS, ERP and many other three-letter acronyms.

One of the problems might be, that the dns caching time has a very high value like one day or worse. Even if your own dns server has a low value like 30 seconds other servers might not respect that and nonetheless cache your ip addresses for hours or longer.

A solution for that is proxying the request from the old server to the new one. This can be done in apache with the following config. The documentation can be found in mod_proxy from apache.

I’m no expert on this topic, so please make sure to read the documentation in case I write nonsense. What I can tell is, this configuration works for us.

    #HTTP Configuration, HTTPS is below and commented!
 
    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://new.server.ip.addr:80/
    ProxyPassReverse / http://new.server.ip.addr:80/
    ProxyPreserveHost  On
    <Location />
        Order allow,deny
        Allow from all
    </Location>
# Do not allow apache to be used as forward proxy
    ProxyRequests Off
# Allow proxy to pass all content
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
# Forward everything below / to new.server.ip.addr
    ProxyPass / https://new.server.ip.addr:443/
# This directive lets Apache httpd adjust the URL in the Location, Content-Location and URI headers on HTTP redirect responses. 
    ProxyPassReverse / https://new.server.ip.addr:443/
# When enabled, this option will pass the Host: line from the incoming request to the proxied host, instead of the hostname specified in the ProxyPass line.
    ProxyPreserveHost  On
# Allow connection to https
    SSLProxyEngine on
    <Location />
        Order allow,deny
        Allow from all
    </Location>

Maybe you need to active a couple of apache modules first, I activated the following, but it might be, that you don’t need them all.

sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http

Leave a Reply