504 after switching DNS to Cloudflare

I wanted to add Cloudflare protection to two API endpoints. After changing my nameservers to the ones shown on Cloudflare dashboard, requests to those hosts started to 504. From the Cloudflare dashboard, I tried adding new A records to these two hosts, which did not resolve the problem. I then reconfigured my nameserver away from the Cloudflare NS and back to their original configuration, and the problem went away. What must I do to enable protection for these hosts?

What have you attempted to resolve this issue @noc22?

Screenshot 2023-08-29 at 10.24.38 AM

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 reviewed that information. This is on an API endpoint, so the “color page with Cloudflare branding” does not apply. The 504 was observed in browser dev console under Network tab.

Can you see cloudflare in the console error?