I have a very simple website that I want to host in a GCP bucket. I want it to only use http (not https) and don't want to add a load balancer and most examples of static GCP websites show adding a load balancer.
The only example I could find without a load balancer shows pointing a CNAME record to c.storage.googleapis.com which would connect to the bucket that's named www.mysite.com.
So far, that works fine except that it doesn't include access to the domain without the www subdomain attached (mysite.com). And, I can't attach an ALIAS record that just points mysite.com to www.mysite.com because Google Cloud DNS doesn't have ALIAS records.
It seems like there would be a pretty simple solution but I'm stumped.
By design you cannot create a CNAME record in a "root" domain level. It has to point to a subdomain. Unless you're pointing it to other domain.
By design buckets are served using
CNAME
record such aswww.mysite.com
pointing toc.storage.googleapis.com
.So you're forced to use
www
prefix or other subdomains.There's a mention in the documentation of a possibility to serve bucket using
A
record.But it's a "brittle and hardwired" solution
You need to create bucket named "mysite.com" with the copy of your site.
Then you go to your managed zone and edit
A
record to point to the IP ofc.storage.googleapis.com
which is74.125.143.128
(at least at the moment I was writing this). Next you change your CNAME recordwww.mysite.com
to point tomysite.com
to redirectwww
to non www.Then wait until the changes propagate and you're set :) I tested it and it works. I don't like to wait so I changed TTL's of all records involved to 1 minute.
Then you'd ask yourself why I wrote it's "brittle and hardwired" ? It will work until someone will change the IP of
c.storage.googleapis.com
. Maybe there is some other way to set up DNS records to point to c.storage.googleapis.com instead of IP but I wasn't able to figure this out.If you don't change your CNAME record and leave it pointing to
c.storage.googleapis.com
then you can have to sites (identical or not it's up to you). One available withwww
- other without.