Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to host an entire site on Google Cloud Storage?

Is there any way to host an entire site on Google Cloud Storage? That is, map a bucket directly to a top level domain.

E.g. create a bucket called mysite.com, then when the user visits mysite.com serve the content directly from cloud storage?

I see how to CNAME a subdomain, e.g. static.mysite.com, but can't figure out how to map the top-level domain to a bucket.

Any solution?

like image 285
rossmckegney Avatar asked Dec 22 '13 16:12

rossmckegney


People also ask

Can I host my website on Google Cloud?

Use our free trial to start hosting your website or web app with any Google Cloud product. Watch an overview on how to build and host a website on Google Cloud. Learn how to serve or migrate a website or choose an option in our technical article.

Can I use Google Cloud as a server?

With Google Cloud, anyone can easily spin up a virtual machine in seconds and use it as a worry-free alternative to a physical server. Because all resources are virtualized, it's possible to effortlessly add more processing power or storage on demand, so you always pay only for what you use.


4 Answers

I wanted to do this too. But there is currently no way of binding Google Cloud Storage buckets directly to a top-level domain name, as you found out.

The IP addresses where Google Cloud Storage answers web requests change often (to adapt to changing conditions on the Internet), so Google doesn't want to you add a subset of those (which would quickly get out of date) as A records for the DNS server of your website. Google instead requires a CNAME to a DNS name it controls, so it can change the IP addresses for Google Cloud Storage as often as it needs to. And a CNAME can only be added to a subdomain and not a top-level domain. (This is because when there is a CNAME at a given level, the DNS server for that domain will not answer any other queries for that level. But a top-level domain needs to answer also at least NS and SOA queries.)

The only workaround for this right now is, as described in another answer, to set up the CNAME for the www subdomain, and configure your DNS hosting service to do a http-level redirect from the top-level domain to the www subdomain. (Mosty providers will support that.)

If you're not a fan of this solution (like me), there are exactly three possibilities. The first one is to wait for Google to offer the possibility to host top-level domains on Google Cloud Storage. That requires Google to DNS hosting, first though. Enabling top-level domain support would require extra work on Google's part (after building their DNS hosting offering), but it's only possible if Google controls both parts. I have no clue if or when Google will ever offer that, though. But one can hope.

The second solution is to switch to another big provider. Amazon can host static websites from S3 on a top-level domain. But that's because they also host DNS for that domain. There may be others. All large cloud providers will serve data from a set of frequently-changing IP addresses. So if they don't host your DNS too, they will need you to set a CNAME on a subdomain.

The third (theoretical, at least) solution is to switch to a smaller cloud provider, offering equivalent service, maybe on OpenStack, etc. Because they're smaller, their IP routing setup will be quite a bit simpler than the big players (Amazon, Google, etc.) and they would then be able to give you a small set of IP addresses to set as A records on your top-level domain. This is just an educated guess on my part, though. I don't know right now of any such smaller cloud storage providers.

(Well, okay, the fourth possibility is to give up on the idea of hosting your website statically. But personally, I really like this option when possible, at least from a security and responsiveness point of view.)

like image 109
Christian Hudon Avatar answered Oct 17 '22 20:10

Christian Hudon


This is an old question, but in case anyone comes across this post- I encountered the same issue today.

Google Domains is my domain registrar. Assuming this is also the case for you, here's how you would set it up:

Under "Custom resource records"...

Create a CNAME record for "www" that points to "c.storage.googleapis.com".

Under "Synthetic records"...

Choose "Subdomain forward". Enter "mydomain.com" in the left-most (subdomain) input and "www.mydomain.com" in the right-most (destination URL) input.

like image 11
bvaughn Avatar answered Oct 17 '22 21:10

bvaughn


It's been a few years, but to anyone facing the same issue (mapping a "naked domain" to a GCS bucket), I see a couple of ways of achieving this.

One is to use any DNS provider that supports "CNAME flattening" (aka ALIAS, or ANAME records). Examples are: DNSimple, NS1, Dyn, DNS Made Easy, and Cloudflare.

Cloudflare is also one of the recommended ways of serving your bucket through HTTPS, and might also save you some money on your egress bill.

Another option, is to use this project to serve your files through App Engine. You get SSL for free, can use it on your "naked domain", and it allows you to configure redirects, rewrites, and custom headers.

like image 2
Nuno Cruces Avatar answered Oct 17 '22 22:10

Nuno Cruces


An alternate solution is to use CloudFlare (free), they allow support CNAME on the Zone Apex / Naked Domain / Root Domain. It works fine for my static site on Google Cloud Storage.

This still leaves the issue of the www ....

The solution that works for me is using CloudFlare is 1. set both www and the naked domain CNAME to c.storage.googleapis.com 2. set a 'Page Rule' for example.com/* to 301 to http://www.example.com/$1

This now means my whole site is on GCloud Storage ( ignore my self comment below as that was before I found 'Page Rules' )

like image 1
Alan Fuller Avatar answered Oct 17 '22 21:10

Alan Fuller