Bad gateway (502 errors) is, for sure, networking. Not sure that one can do much just Moodle to fix that - after all it's the resource inside the server, behind the OS firewall, and any network firewall one might have in front of the server itself.
Do have a CentOS 7 sandbox server however. The new firewall on CentOS 7 much different than CentOS 6 or 5 (iptables) It now has zones and settings for protocols/ports per zone. Not only that, but, if you are not hosting this on your own network, it's remotely hosted ... like on Rackspace or something similar ... they too, even with un-managed servers .... are starting to use IPv6.
Suggest installing iptraf on server and running it in a terminal session while from another workstation, accessing Moodle and editing whatever.
In that problem I mentioned ... weird behavoir never before witnessed ... and whose solution was to disable YUI ... the other strange thing ... in Moodle's logs, I'd see the admin user access recording an IPv6 address and not an IPv4 as his access has always shown to Moodle. In my case, hosted on Rackspace, cannot disable IPv6 ... don't know that Moodle actually supports it ...
So ...
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7
Disable IPv6:
https://www.unixmen.com/disable-ipv6-centos-7/
Am by no means a CentOS 7 expert and it's hoped that checking the above might help find the cause of the gateway error.
'spirit of sharing', Ken