I recently bought a new domain and tried to setup the DNS with Cloudflare, everything seems to be working fine. But, when I tried with www in front of my domain, I was getting this below Error 522 Connection Timed out.
I was looking all over the place in Cpanel, WHM to fix the issue. I was writing re-write rules in .htaccess file that has script for redirect using apache given by host. But, what I missed was the DNS config on the Cloduflare side. The key thing missing was that I did not had a CNAME record. It was pointing to some weird server. Anyways, if you add or change your CNAME record to point to your right server / domain name, it will work fine. I have done it like below. It worked like a charm.
So, key thing to do is point the CNAME to your domain name and A record should point to the IP Address in Cloudflare to avoid this error.