How to use CNAME to properly redirect subdomain from host to Google Cloud

2.5k views Asked by At

I have outlined my issue below in list format for clarity:

  1. I have a subdomain named clouddemo.camerontaylor94.com
  2. I used a CNAME record to redirect the subdomain to c.storage.googleapis.com
  3. On Google Cloud, I have a bucket named clouddemo.camerontaylor94.com (exactly the same as the subdomain
  4. I uploaded html files, a css file, and some various text files to make up a resume website into the bucket with the exact same file path as in my host
  5. When I go to clouddemo.camerontaylor94.com in my browser, the error "Invalid Bucket Name" appears, and the URL changes to simply c.storage.googleapis.com
  6. Why is the bucket name invalid - shouldn't it be exactly like the subdomain name?

Thank you!

2

There are 2 answers

2
Christiaan On

To use your bucket as a static site you need to configure it first using gsutil:

https://cloud.google.com/storage/docs/website-configuration

You probably need to upload an index.html and 404.html to your bucket and then run this:

gsutil web set -m index.html -e 404.html gs://clouddemo.camerontaylor94.com
2
Brandon Yarbrough On

You're not using a CNAME redirect. Instead, you're using an HTTP 301 Redirect.

The DNS entry "clouddemo.camerontaylor94.com" has a DNS A record resolving to some nginx server somewhere. That server takes in HTTP requests and responds with a 301 Redirect to http://c.storage.googleapis.com/.

A CNAME redirect works differently. Instead of using a web server, there is a DNS entry that says "this DNS name is equivalent to this other DNS name." The client sees this when it looks up the DNS record and goes straight to the second source.