How can I use Cloudfront with a root domain name?

2

I set up a Cloudfront distribution. I use a non-AWS domain registrar and DNS. I want my distribution to respond to "https://mydomain.com", but there is a problem. Cloudfront provides a domain name and asks you to create a CNAME record in DNS, but you can't create a CNAME record that points to the root domain or "@", like you can with a regular A record.

To get around the problem, I set up "www.mydomain.com" as the CNAME record. If I type "https://www.mydomain.com" into my browser it works, but of course "mydomain.com" without "www" does not work.

The next thing I did was create a permanent redirect in DNS that should redirect mydomain.com to www.mydomain.com. Now I can type "http://mydomain.com" and it redirects to www.mydomain.com and it works. But if I type "https://mydomain.com" (with HTTPS instead of HTTP) it does not work. I presume that this is because whatever server is implementing the redirect (I use GoDaddy) doesn't have my SSL certificate so the connection can't be made.

I'm not sure how to resolve this problem. What I need, I think, is some web server that is on a fixed IP address and also has my SSL certificate, and can simply respond to all requests with the permanent redirect response. The only way I can think of to do this in AWS would be to set up an entire EC2 instance with my own web server, which is a lot of work and cost. Is there a better solution?

My company doesn't want to move our DNS or domain registration to AWS, so using something like Route 53 is probably not an option.

Thanks, Frank

3 個答案
0

Hi Frank,

Depends on your DNS provider, AWS provides alias records within Amazon Route 53 and you can create an alias record at the top node of a DNS namespace, also known as the zone apex (sometimes called naked domain).

Several DNS providers have custom solutions to work around this problem too, including:

  • ALIAS at DNSimple
  • ANAME at DNS Made Easy
  • ANAME at easyDNS
  • CNAME (virtual) at CloudFlare

Best Regards,

Ricardo Makino

profile pictureAWS
已回答 1 年前
0

It seems now that it is possible to use CNAME apex.

There was an update in specification, more details in this stackoverflow: https://serverfault.com/a/947095

I personally was able to set apex CNAME on my domain on my dns provider, which redirects to cloudfront distribution where I host my single page application.

Everything works!

So now it is just a matter of whether your DNS provider supports apex CNAME records.

已回答 6 個月前
0

The solution that worked for me after struggling through a lot (I am using the hostinger DNS) :

  • Delete the A record that points to the static IP and add an ALIAS record instead that is pointing to the CloudFront URL
  • After that add a CNAME record with www so that it points out the root domain i.e. mydomain.com.

Please note down the A record before you delete in case if it doesn't work for you

Sachin
已回答 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南