0

Note - I see several other questions asking about redirecting to the root of their S3 static websites, but I didn't see anything about redirecting from the root of a domain name to a CloudFront/S3 site.

I have my personal website deployed to AWS CloudFront & statically hosted on S3. I have a www. CNAME record pointing to the CloudFront hostname, and that works properly, but I've discovered that you can't have a CNAME record for the domain root. I already have a VPS with nginx that's hosting several of my other projects - is it fine to simply add an A record from the domain root to my VPS IP, and have nginx redirect requests for the domain root to the CloudFront hostname?

Edit: to clarify - what I would like to happen is for all traffic heading to example.com be forwarded to the CloudFront hostname assigned to my website. I am able to do this with www.example.com by creating a CNAME record for 'www.' pointing to the desired hostname. However, it appears that Google Domains does not allow CNAME records to be created for the root (i.e. just example.com), and so I am wondering how to forward traffic from example.com to my CloudFront hostname (as opposed to what I can do right now, which is only to forward www.example.com to cloudfront).

And in case it's relevant, I can't do any sort of wildcard redirect because I am using other hostnames on the domain for different projects that require specific A records.

And would this be an acceptable/good practice nginx configuration for the site? I think it would work because www.example.com is already properly forwarding to the CloudFront hostname.

server {
        listen 443 ssl;
        server_name example.com;
        rewrite ^/$ https://www.example.com permanent;
        ssl_certificate           /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key       /etc/letsencrypt/live/example.com/privkey.pem;
}
3
  • I'm confused. Can you edit your question to describe your problem better, rather than just suggesting an end state?
    – Tim
    Jan 30, 2022 at 4:31
  • @Tim I think that's a bit clearer now Jan 30, 2022 at 17:09
  • Not really. You're mixing together your assumptions, current state and target state, problem, and proposed implementation. For example, you mention a server and domains, but are they different domains, subdomains, or just directories off this domain? You also say "forward traffic", but that's implementation, it might just be a domain resolution. I suggest you delete this question and start again, writing it to make it easy for others. Suggest two sections "current state" and "target state", and make sure you cover what you're trying to achieve without any assumption about implementation.
    – Tim
    Jan 30, 2022 at 19:39

2 Answers 2

0

By domain root, I assume you mean example.com, instead of www.example.com, and that you want to point that to your AWS cloud web app. One thing you can do is create an A record named @, which essentially says "this is me. Any DNS requests to me (example.com) should go to this IP address." Then add a CNAME www that points to @. You can use Nginx if you want, Nginx used for pass-through is just a reverse proxy. It will act as a middle man of any requests between the client and the server. Nginx just repeats those messages between the client and the server.

I hope that was any help, my feeling is I read the question wrong

2
  • Ok I'm a little confused, with that setup, what is the purpose of the CNAME record pointing to @? Can't I just create the A record that points to my nginx server and do the forwarding like you said? Jan 30, 2022 at 17:12
  • Yeah. That would be perfectly fine. Just have it pass_thru to the server you want it to, and set your A record to the nginx server.
    – Alex
    Jan 31, 2022 at 10:38
0

If you migrate your domain to AWS' Route53 service, this is very easy. You simply use the wizard to create an Alias record, which is a route53-specific feature. With an Alias you can point the zone apex (your example.com) to the Cloudfront Distribution, and then just create a second record that for www that also is an alias to the CF distribution.

Migrating between registrars is also quite simple - I did this myself from 123-reg to AWS last year and it was pretty much painless.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .