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 ( 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. (

Where am I going wrong here?


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.

Leave a Reply