What can I do to fix the 504 gateway timeout error?
There is nothing you can do.
You send a request to the server. This particular request fails because the server sends a proxy request and receives a timeout error. Your server reports this to you as a 504 status.
The only way to fix this is to fix the proxy (make it respond in a timely manner) or change the server so it doesn't rely on that proxy. Both are outside your area.
You cannot prevent such errors. What you can do is figure out what the user experience should be when a problem like this occurs and implement it. BTW. If you are getting 504 errors then you should expect timeout errors as well. Let's say you make a request to your server with a 60 second timeout, and your server requests a proxy with a 60 second timeout. Since both timeouts are the same, sometimes your server will receive the proxy server timeout and send it to you (status 504), but sometimes your request to the server will timeout before that and you will get a timeout error.
source to share