It has been observed that some servers do not like re-using a connection for submitting data(POST), which results in a connection reset to the Linux Access Gateway Appliance.
If your users are reporting frequent 504 errors, its highly likely that you may be facing the above behaviour.
To work around this problem, it is recommended to turn off the 'connection presistence' to these backend servers.
There are also other causes for 504 errors to be generated by Linux Access Gateway Appliance, which includes:
The webserver(s) not being available at that time.
The webserver(s) being slow at times, possibly because of load ( in this case, a higher data read timeout configuration might help).