Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CloudFront with a single EC2 instance without a load balancer

I recently migrated my WordPress to an EC2 instance. I attached an Elastic IP address to it and created an A record in my Route 53. But all my requests were HTTP so I wanted to use CloudFront to redirect all my HTTP to https.

I created a CloudFront distribution and now all my HTTP requests are redirected to https. And since my SSL certificate is active, my site is secure.

But now my site (blog.insisivecloud.io) doesn't load and I get a 502 Error which says "CloudFront wasn't able to connect to the origin." I have given the public DNS of the EC2 instance as my origin.

When I go to the public DNS of the EC2 where the blog is hosted it works fine. (ec2-54-167-212-65.compute-1.amazonaws.com)

Where am I going wrong here?

like image 394
Shivaranjani Ramakrishnan Avatar asked Mar 21 '19 04:03

Shivaranjani Ramakrishnan


1 Answers

As official documentation says:

For HTTPS viewer requests that CloudFront forwards to this origin, one of the domain names in the SSL certificate on your origin server must match the domain name that you specify for Origin Domain Name. Otherwise, CloudFront responds to the viewer requests with an HTTP status code 502 (Bad Gateway) instead of returning the requested object. For more information, see Requirements for Using SSL/TLS Certificates with CloudFront.

like image 190
Rustamjon Kirgizbaev Avatar answered Sep 24 '22 16:09

Rustamjon Kirgizbaev