0
votes

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.

https://example.com

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.

1
Have you inspected CloudWatch metrics for the instance, or sshed into it and checked there? Is CPU high, mem usage high suddenly, or some other anomalies which you can observe?Marcin

1 Answers

0
votes

There are factors of static web page performance if you combine it with CloudFront but I doubt this is related to static contents.

  • Use local caching for static contents as those will not change immediately.
  • Your CloudFront distribution mode is compressed or not? if Compress Objects Automatically = YES, CloudFront will compress and serve the contents which is much faster.
  • Try to use cache behaviors for static contents.