Hosting a website on EC2 is simple -- but it's not that scalable, say what if 100s of requests are flooding through your application/website. Headache, right!! In this post, we will set up a highly available and performant website using Application Load Balancer (ALB), EC2, and CloudFront for Efficient delivery.
We will go through a step-by-step process to achieve this, and I have also included real screenshots and steps so even beginners can follow along.
Final result? A public-facing website that is delivered worldwide, served through Cloudfront (CDN). Interesting, right? Let's get started. 🚀
📦Step 1: Launch an EC2 Instance
(I already set up an EC2 instance with a basic website (HTML, CSS) and served it using Nginx.)
Setup details
Installed Nginx + uploaded site files
And make sure to allow only necessary security groups for better Security reasons. In my case, on my EC2(security group), I allowed ports 22,80.
After the Basic website setup, you can see that the site can be accessed by the public IP of my EC2 Instance.
🛠️Now Comes the Real Game: Scaling It Up with ALB and CloudFront
So far, we’ve deployed a simple website using an EC2 instance. That’s a great start — but it’s not scalable, not fault-tolerant, and not production-ready.
In the next steps, I’ll take this basic setup and upgrade it to a high-performance architecture using:
✅ Application Load Balancer (ALB) to distribute traffic
✅ CloudFront to deliver content globally with low latency
✅ Tighter Security Groups to expose only what’s needed
⚖️Step 2: Configure the Application Load Balancer (ALB)
Name the LoadBalancer and make it a public-facing loadbalancer, as we need to serve the traffic from users/public. Click next.
Here, select the VPC (default VPC) and also select the Availability zones and subnets. I'm selecting two subnets for higher availability (us-east1a and us-east1b). Click next.
Next step is to create the Security group for the LoadBalancer In my case, I'm creating inbound rules on ports 80,443.
Name The Target Group and in that page that's all we need for now leave all as such to Default.
Now we need to register the targets as we are using the ec2 instances select those ec2 instances and click include as pending below. That's it.
Wait for few minutes before the loadbalancer gets fully set up and ready to serve the targets, That is our EC2 Instance. Once it becomes active, copy the loadbalancer's DNS name to access our website.
Voila! Now we are serving our website using a load balancer's(DNS NAME!!!), but wait we are not done yet, we need to set up an CloudFront distribution.
🌐 Step 3: Setup CloudFront
- Search for CLoudfront on the aws console
We need to Create a new cloudfront distribution, name your distribution and select the single website or app.
Now Select the origin type as Elastic load balancer and choose your load balancer below.
Here in Security, if you need AWS WAF(Web application firewall) capabilities you can opt for here I'm selecting (Do not enable WAF).
Now here Review the changes we did and proceed to create our distribution.
Wait for few minutes to make the distribution to propagate fully and become active.
Important step as we going with a sample go through on setting up an HTTP site, we need to setup the protocol to HTTP only.(If you are using the Custom domain or HTTPS , SSL certs make sure to turn on to HTTPS.
After few minutes you can see the last modified to deployed our site is ready for production.
🎉 Final Step: Access Your Website via CloudFront
Now, take the CloudFront distribution domain name (something like d1234abc.cloudfront.net) and open it in your browser. You should see your deployed website loading fast, served securely through CloudFront, routed via your Application Load Balancer, and ultimately hitting your EC2 instance.
✅ Boom! You've just built and deployed a highly available, scalable, and globally optimized website using AWS infrastructure.
From a simple EC2 instance to a fully distributed setup — this is how real-world deployments scale.
🙌 What’s Next?
- You can now explore:
- Adding SSL using ACM
- Custom domain via Route 53
- Auto scaling your EC2 instances
- Logging and monitoring with CloudWatch
Top comments (2)
Very useful
Well done bro