0

We have 2 servers. During maintenance on our primary server 1, we want server 2 to serve a "temporarily offline" page. We're doing this by simply creating an account for the domain on both servers and adding both nameservers to the domain registrar like so:

NS1.SERVER1.COM
NS2.SERVER1.COM
NS1.SERVER2.COM
NS2.SERVER2.COM

This works great and when server 1 goes offline, server 2 immediately serves the maintenance page. The issue is that server 2 is then cached in the browser/ISP DNS cache and even after server 1 comes back up, visitors still see the maintenance page.

Is there some way to disable DNS caching on server 2 via PHP or Apache?

cronoklee
  • 6,482
  • 9
  • 52
  • 80
  • 1
    Reduce the DNS entry's TTL value, so the client will fetch it again very soon. – deceze Mar 04 '21 at 14:26
  • Thanks @deceze. I thought the same but I cant figure out where to do that. Would that be on server 2? – cronoklee Mar 04 '21 at 14:59
  • No, in your DNS configuration. You're talking about a level lower than HTTP, so the server has nothing to do with that yet. It's just about the name resolution pointing the domain name to your server's IP address. Your DNS server should hopefully allow you to set a TTL value for your DNS entries. – deceze Mar 04 '21 at 15:08
  • 1
    Not sure DNS is really the right strategy for a maintenance page the way you're doing it. You're saying you've configured both servers equally in your DNS; i.e. a DNS query for your domain name may equally return either IP address or both. Then it's still possible for a client to hit your offline server. It's not typically going to retry using a different DNS entry if the first one failed. That's "failover" at the wrong level. – deceze Mar 04 '21 at 15:11
  • You probably want just one DNS entry pointing at a load balancer, which directs traffic one way or the other based on the server health. Or possibly a CDN with a custom error page configured. – deceze Mar 04 '21 at 15:12
  • Also, if you do use this "DNS failover" strategy, you *generally* need to lower the TTL way down, if your server may suddenly go into maintenance at any moment, otherwise nobody will switch over to the other address until the DNS entry has expired. And a very low TTL will just cause a lot of traffic _and_ slow down clients who constantly need to query for DNS again. – deceze Mar 04 '21 at 15:14
  • This will only work if you have planned maintenance windows. Then you need to lower the TTL in advance before maintenance begins (at least as much as your current TTL is), then change your DNS entries to the maintenance server, wait for the amount of TTL to ensure all clients' DNS has expired, then do your maintenance, then switch the DNS back and up the TTL again. – deceze Mar 04 '21 at 15:16
  • @deceze Thanks a lot for the advice. I cant control the TTL at the registrar. Using nameservers means the DNS is hosted by server 1. Since server 1 is just vanishing during downtime, server 2 takes over as the DNS authority. I'm thinking I could turn the TTL way down here so all users instantly connect to server 2 and then see the 1 minute TTL. I am concerned about what you said about users randomly connecting to server 2 tho :/ – cronoklee Mar 04 '21 at 15:26
  • The servers are simultaneously HTTP *and DNS* servers?! Mmmkay… And yes, if you set both servers to be authoritative name servers for your domain, then a client may choose any one of them to resolve the IP. – deceze Mar 04 '21 at 15:29
  • Yes. Crap I assumed it was a hierarchy like MX records or similar. Damn ok we'll have to set up a 3rd server as a controller then. Thanks again – cronoklee Mar 04 '21 at 15:33

0 Answers0