1. Prepare an EC2 Instance with a Deployed Website
You’ll first need a running EC2 instance that already hosts a website, such as one using Nginx or Apache.
✅ Example: If you visit http://your-ec2-public-dns/, you should see your homepage loading correctly.
2. Create a CloudFront Distribution and Set EC2 as the Origin
Step 1: Open the CloudFront Console
- Go to the AWS Management Console, search for CloudFront, and open it.
- Click “Create Distribution.”
Step 2: Configure the Origin Domain
- In the Origin Domain field, paste your EC2 public DNS, for example:
ec2-xx-xxx-xx-xxx.compute-1.amazonaws.com
- Protocol: Choose “Only HTTP.”
- Leave other settings as default.
Step 3: Choose a Cache Policy
- Select “CachingOptimized.” This is CloudFront’s default high-performance caching policy.
Step 4: Disable WAF (Web Application Firewall)
- If you haven’t configured AWS WAF, choose “Do not enable security protection.”
Then click “Create Distribution.” CloudFront will start deploying your setup.
3. Verify That CloudFront Is Serving Your EC2 Website
Once the deployment is complete, CloudFront will generate a unique domain name like:
dxxxxxxx.cloudfront.net
To verify:
- Open the CloudFront domain in your browser.
- If your website loads, it’s working!
- If you see a 502 error, try the following fix:
Fixing 502 Errors:
- Go to CloudFront → Distributions → Origins.
- Edit the origin settings and set the Protocol to HTTP.
- Save and wait for redeployment.
- Refresh your CloudFront domain — your site should now load normally.
4. Confirm That Requests Are Coming from CloudFront
You can verify this using your browser’s Developer Tools (F12 → Network tab):
- Look for headers like:
via: 1.1 dxxxx.cloudfront.net (CloudFront)
x-cache: Miss from cloudfront 或 Hit from cloudfront
These indicate CloudFront is successfully caching and delivering your EC2 website content.
5. Conclusion
By following this guide, you’ve successfully integrated your EC2-hosted website with CloudFront, enabling global acceleration and improved availability.
This is a key step toward building a scalable, reliable cloud architecture.
At Elite Cloud, we’re an official AWS reseller and advanced consulting partner, helping businesses:
- Launch and optimize AWS environments
- Manage billing in NTD with local invoicing
- Access exclusive pricing and technical support
Whether you’re migrating to AWS or upgrading your cloud setup, Elite Cloud offers 1-on-1 expert guidance to make it simple.
📌 Want to explore more CloudFront optimization tips or need help improving your cloud architecture? 👉 Contact Elite Cloud today.