I deployed a PHP website on EC2 Micro instance with OpenLiteSpeed web server and the website is working perfectly fine when called with its domain.
It's configured to work with any Listener Host so the is working fine when called using
ec2-123.123.123.123-ap.region.compute.amazonaws.com
I configured the CloudFront with the origin as ec2-123.123.123.123-ap.region.compute.amazonaws.com
and it generated a cloudfront URL like https://blahblahblah.cloudfront.net and this link too working perfectly without any issues.
But when I change the Route 53 DNS A record for the domain from server IP to the CloudFront distribution the server was extremely slowed down.
Even when I call the site with either way
https://example.com
ec2-123.123.123.123-ap.region.compute.amazonaws.com
https://blahblahblah.cloudfront.net
The website is extremely slow and the browser network console is showing around 2 mins of TTFB wait time.
When I update the A record back to the IP instead of CloudFront distribution, the site responds in 80 milli seconds.
Initially, I thought it speeds up after a few hours but that didn't happen even while leaving the site for around 4 hours.
Note: I am not using ELB here, connecting CloudFront straight to EC2 instance.