Thanks for the detailed guide on error 504. These are the main reasons that are not difficult to find and fix. I also use a monitoring service to quickly detect such problems and get notified when they happen.
I faced a similar problem today too. My site monitoring warned me about a 500 error, a server error occurred. After 10 hours everything is working properly again. But I was unable to figure out the reason for this failure.