That is because of SE Linux.
To fix it:
/usr/sbin/setsebool httpd_can_network_connect true
Or you can also set the security settings,
-> Go to Security Level configurations and Change Tab to SELinux
And modify SELinux policy Check
Allow HTTPD scripts and modules to connect to the network
under HTTPD service