I am getting 504 Gateway Timeout errors periodically on several sites. I am running on AWS and Digital Ocean Ubuntu 18 virtual servers. Bandwidth, RAM, CPU load, and disk space all show no issue. The virtual servers are websites are running WordPress with light to medium load. I sometimes see the 504 Gateway Timeout error trigger when a simple admin change is made s(uch as a post update) to one site or a relatively intensive page is accessed. Then, once the error starts, trying to view any page on the site, and in many cases any page on any website on the same server, also gives the 504 Gateway Timeout error. Usually it resolves itself after 5-30 seconds, however this downtime is still unacceptable.
Are there any steps to avoid this error to help prevent downtime?
Are there any steps to help one virtual server not affect other virtual servers? Sandboxing or limiting the resources to cap resource allowance?