Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Cloudflare with Amazon EC2 and load balancers

I am running my website on AWS.

I have one load balancer for my two web servers. My load balancer doesn't have a static IP address, it has a domain name.

I want my traffic to come only via the load balancer. I am using Cloudflare's DNS instead of Route 53, because that's what the Cloudflare instructions said.

I cannot add the load balancer's IP as an A record because it is dynamic and cannot be added through Cloudflare's DNS panel (Not like Route 53). Help me I am stuck in this situation. No solution is offered by Cloudflare so far.

Has anyone faced the same issue?

like image 315
Arjun Kapoor Avatar asked Oct 11 '14 03:10

Arjun Kapoor


People also ask

Can you use Cloudflare with AWS?

Cloudflare integrates quickly and easily with AWS. Host your websites and run applications on AWS while keeping them secure, fast, and reliable. Use Cloudflare as a unified control plane for consistent security policies, faster performance, and load balancing for your AWS S3 or EC2 deployment.

Does Cloudflare do Load Balancing?

Cloudflare Load Balancing distributes traffic across your servers, which reduces server strain and latency and improves the experience for end users. Free, Pro, and Business users can enable Load Balancing in their Cloudflare dashboard Open external link .


3 Answers

You can set your Cloudflare record as a CNAME alias of your ELB's A record

See: https://support.cloudflare.com/hc/en-us/articles/200168986-How-do-I-add-a-Amazon-ELB-Elastic-Load-Balancing-record-to-CloudFlare-

like image 90
Dmitry Mukhin Avatar answered Oct 18 '22 23:10

Dmitry Mukhin


I suggest to manage your domain DNS with CloudFlare. Add a CNAME record for your subdomain demo which points to that IP. On CloudFlare Console go to Crypto > Origin Certificates. Create a new one with RSA, then import it to AWS Certificate Manager at us-east-1. For the certificate chain use this. Be sure that Always use HTTPS in Crypto tab is on. After some minutes you should be using your domain pointing to AWS with HTTPS working fine.

That's what I did to make a subdomain to work with an AWS API endpoint with SSL.

like image 2
Steven Avatar answered Oct 18 '22 23:10

Steven


I decided like this:

I created in the cloudflare, in the DNS table, two CNAME records that point to the dns name of the load balancer generated in aws.

The first record created must contain in the "Name" field, the value "www" with the "content" field pointing to the url of the load balancer in aws. The second record, on the other hand, points to root, containing the value "@" in the "Name" field and "Content" pointing to the same load balancer server in "aws".

See the images below for a better understanding.

enter image description here

like image 1
Wedson Quintanilha da Silva Avatar answered Oct 18 '22 23:10

Wedson Quintanilha da Silva