Nodejs app gives 502 error if cloudflare proxy is turned on

I have hosted an Angular SSR (NodeJs) application in my IIS (Windows VPS).

It is working if Cloudflare Proxy is turned off. But if Cloudflare Proxy is turned on it shows the 502 error, please find the attached screenshot for the same.

Please help with it. we are on live.

There is no screenshot attached, but…

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.

I also have the same problem

1 Like

Same problem in several of my projects.
It doesn’t depend on my servers.

Some websites are slow and Cloudflare gives 502 or 504 gateway errors. Other websites on the same server through Cloudflar are fast.

I enabled “Development Mode. Temporarily bypass our cache. See changes to your origin server in realtime.” Gateway error goes away!

I have found the root cause for this. If I enable Full or Full (strict) SSL modes in Cloudflare. I’m getting a 502 error. But my server has already been configured with the Let’s Encrypt certificate.

Can someone have a solution for this?

Is your server allowing port 443 traffic from Cloudflare?

Yes, Here I am allowing 80, 443 ports

And Scope set to Any IP Address.

Have any thoughts?

You shouldn’t be using that in the first place.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.