Error 522 and 524 on CF, Websites not working

Here is the background. I was using cyberpanel v2.0.3 on digital ocean with 2gb ram. I am having 8 websites. since Lets Encrypt certificate was not working. I added 2 of my sites to cloudflare. couple of days before I was having 522 and 524 error on two of those sites and rest of the sites just was not openeing. so i upgraded my server to 4gb ram. I increased php memory and other things. But after some times websites show same error.
Whenever I restart PHP, websites starts to work but after some times shows this error.
Here is what I tried:

  1. whitelisted all cloudflare ips
  2. tried to disable CF but certificate error appears
  3. disabled default firewall and enabled CSF

I don’t know further what to do.
If I have to upgrade cyber panel. Is there any chance of failure?? I dont want to lose my data.