Cloudflare shows error 502 in my website. What is the solution for problem

When i enable cloudflare in my website it shows error 502 in which it indicates that error of hosting. But disabling cloudflare this error does not show. What is the solution for this. thanks

The 502/504 errors are caused by a problem connecting to an upstream server - meaning your server is trying to initiate a process and this fails to work as expected or times out. In most cases of 502 / 504 errors, back-end servers are not communicating correctly. When this happens, you will see color page with Cloudflare branding and the Error 502 Bad Gateway or Error 504 Gateway Timeout. Review this Community Tip for fixing 502 or 504 gateway errors.