The best/official answer is per JinnFox to use a load balancer (or some http proxy). In this solution, a monitor to determine web server health can redirect to any number of places when it determines the server node is not taking HTTP(S) requests. Once the node comes back up and starts responding to the monitor, the load balancer should automatically redirect traffic back.
For my setup I have an F5 BIG-IP that not only monitors the HTTPS port via tcp connectivity, but also validates the X509 certificate and ensures a specific content string is returned (from a working HTML page). So even in the event that the server is still up but handling traffic incorrectly, the hardware load balancer can redirect the traffic wherever I want.
I have an TCL script on the BIG-IP to send it to a CDN 404 page if all servers are down (which shouldn't happen).
I know F5 has a lightweight alternative to the more expensive BIG-IP solution that should do what you want and a bunch more. It's always good to have some application logic existing prior to the web server for these and other scenarios. Or there are free ha-proxy solutions but I don't have experience with scripting within these.