
Connect Your Namecheap Domain to Cloudflare
- Add Your Site to Cloudflare: Log in to Cloudflare, click "Add a site," and enter your domain name. Choose the free plan to start.
- Copy Cloudflare's Nameservers: Cloudflare will scan your existing DNS records and then give you two nameservers. They will look something like
ada.ns.cloudflare.comandben.ns.cloudflare.com. Copy these. - Update Nameservers in Namecheap:
- Log in to your Namecheap account.
- Go to your "Domain List" and click "Manage" next to your domain.
- Find the "NAMESERVERS" section and select "Custom DNS."
- Paste the two
nameserversyou copied from Cloudflare into the fields and save your changes.
Set Up the AWS Classic Load Balancer (CLB)
- Navigate to EC2: In the AWS Console, go to the EC2 service. In the left-hand menu, scroll down to "Load Balancing" and click "Load Balancers."
- Create Load Balancer:
- Click "Create Load Balancer."
- Choose "Classic Load Balancer" and click "Continue." (Note: For new projects, an Application Load Balancer is often recommended, but we'll stick to Classic as requested).
- Define Load Balancer:
- Load Balancer name: Give it a simple name (e.g.,
my-web-clb). - Listeners: Configure it to listen for web traffic. Set the "Load Balancer Protocol" to
HTTPwith port80, and the "Instance Protocol" toHTTPwith port80. This means it accepts traffic on port 80 and sends it to your EC2 on port 80.
- Load Balancer name: Give it a simple name (e.g.,
- Assign Security Groups: Create a new security group for your load balancer. This group should allow incoming traffic on
HTTP (Port 80)from anywhere (0.0.0.0/0). - Configure Health Checks: This is a crucial step! The load balancer "pings" your EC2 instance to make sure it's running.
- Ping Protocol:
HTTP - Ping Port:
80 - Ping Path: Use
/or/index.html. This should be a file that actually exists on your server.
- Ping Protocol:
- Add EC2 Instances: Select the EC2 instance you want to receive traffic and click "Add."
- Review and Create: Review your settings and click the "Create" button.
Connect Cloudflare to Your Load Balancer
Now you'll point your domain name to the load balancer you just created.
- Go to Cloudflare DNS: Log in to Cloudflare and go to the DNS settings for your domain.
- Delete Existing Records: You might see old
Arecords pointing to Namecheap's servers. It's usually safe to delete these. - Create a CNAME Record:
- Click "Add record."
- Type: Select
CNAME. - Name: To point
www.yourdomain.com, typewww. - Target: Paste the DNS name of your Classic Load Balancer that you copied from AWS.
- Proxy status: Make sure the cloud icon is orange (Proxied). This activates Cloudflare's security and performance features.
- Click Save.
Final Security Group Check
- Go to the EC2 service in AWS and find "Security Groups" in the left-hand menu.
- Select the security group attached to your EC2 instance (not the load balancer's).
- Go to the "Inbound rules" tab and click "Edit inbound rules."
- Add a new rule:
- Type:
HTTP - Port Range:
80 - Source: Instead of a specific IP, select "Custom" and start typing the name of the load balancer's security group (the one you created in Step 2.4). Select it from the list.
- Type:
- Save the rules.
Enjoyed this post? Read the next one ↗