Some of my tools, mostly "wikidata-todo" (see T341190), randomly start throwing 504 errors. This last one was less than a day after I restarted the webserver manually.
This tool is just a collection of PHP/HTML/JS, nothing crazy. The webservice should not become 504, or at the very least restart itself if that happens.
I will try and move some of the sub-tools to "full" tools, but I will have to leave redirects in place, which will be subject to the 504 errors again.
Please let me know if I can do anything on my side, but this looks like a server issue to me.