What I could suggest here are a few things:
Check the RAM and the CPU usage during the 521 errors
Check your services like Apache/MySQL/PHP and etc. in order to determine if any of them is crashing
Check your server logs for any specific errors
Try to optimize your Wordpress site so that it consumes less resources - for example install a caching plugin, reduce the number of the overall plugins that you are using, optimize your images and etc.
Once you’ve gathered this information then you could take some actions like maybe adding some extra resources like RAM and extra CPUs and/or optimize your services.
In case that you need some extra guidance, you could provide me with extra details on the current setup that you have like what is the web server that you are using, a copy of your log files during some of the 521 errors and etc.