504 Error even though the server is fully functional

Hello, I have similar problem. I was able to re-produce it as well.

Case and the problem;
I have mysite working(mysite.tk). Domain from Freenom. NS from Freenom. I have an Nginx container listening on 443 for the backend to respond. Then I move the DNS to Cloudflare and site continues to work. So far so good.

Then I shutdown nginx and restart it.

Then Error 504 screen gateway timeout;
But, I check and find that;
Nginx is working and responding to ip:port since I can see the responses in the log but not to mysite.tk since there are no logs either. I checked nginx logs and backend logs and could not find any record.

Then I take mysite.tk out of Cloudflare and update NSs in freenom and wait for DNS resolutions. Then again;

Then this time is says 504 Gateway Time-out/nginx;
But, I check and find that;
Nginx is working and responding to ip:port since I can see the responses in the log but not to mysite.tk since there are no logs either. I checked nginx logs and backend logs and could not find any record.

Then I shutdown nginx and restart it.

Then mysite comes back and starts working and add the site to Cloudflare and go to square 1.

I have also found an explanation from hostinger.com that this 504 is not related to the server.

Any suggestions to the problem?

Thanks a lot in advance