27

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?

Unheilig
  • 15,690
  • 193
  • 65
  • 96
rossmckegney
  • 460
  • 1
  • 4
  • 9

8 Answers8

21

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.)

Christian Hudon
  • 1,763
  • 19
  • 39
  • Hi @Christian Hudon You said that one way is if Google offers DNS hosting... Is this what you meant? https://cloud.google.com/dns/ Can you update your answer explaining how to do it with "Google Cloud DNS"? It would be much appreciated since I hate seeing "www" on domains... Thanks, Regards. – Rodrigo Graça Feb 24 '17 at 18:34
  • I could have been more clear, I guess. Google offering DNS is a pre-requisite to them being able to support hosting Google Cloud Storage buckets on top-level domains, but not the only thing needed. Once they are a DNS host, then they control all the pieces they need to implement hosting GCS buckets on top-level domains. Tweaked my answer to be hopefully clearer. – Christian Hudon Mar 03 '17 at 20:37
  • so there's still no solution.... Like you I would like to host my site statically (on Google) and with no www.... (I hate www!) – Rodrigo Graça Mar 04 '17 at 00:31
  • Yeah, basically no solution currently. Either you like Google more — and host there with a "www" — or you hate the "www" more — and host on Amazon S3, say. – Christian Hudon Mar 05 '17 at 16:12
11

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.

bvaughn
  • 12,062
  • 37
  • 43
2

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.

Nuno Cruces
  • 1,234
  • 13
  • 16
1

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' )

Alan Fuller
  • 433
  • 5
  • 12
  • Just want to add, there still is the issue of www. site and non www site - and effectively needing to duplicate two buckets - folder by folder - I haven't got a viable solution for that – Alan Fuller Aug 18 '16 at 19:24
  • By the way - totally solved for me using cloudflare - set up the root domain on Google Cloud and use cloudflare root domain Cname with 'flattening' then use page rules to redirect the www to the root. All works fine for my sites. – Alan Fuller Mar 03 '17 at 11:28
0

@Christian Hudon's answer is very clear. I've been trying to do the same and I've been having the problems discussed above. What you can also do is the following:

Create two CNAME entries one empty (example.com) and another one WWW (www.example.com) Now create two bucket folders: example.com and www.example.com Decide which one will host the pages and assets and which one just the pages.

Let's say www.example.com is the source so you have your folder structure, images, css, javascripts, etc... in there and because the site is static what you can do is to add the full domain on the source of your assets.

Something like

 <link rel="stylesheet" href="http://www.example.com/css/main.css" type="text/css" />

Then copy over the html pages only to example.com. Obviously if you have example.com/contact/index.html you need to create the folder too.

It's a little bit annoying but it was the only way I could get it to work. This is not ideal if you need to change the content quite often but at least it works, it all depends on your needs.

Alfonso
  • 326
  • 1
  • 10
0

One way you can do this is by creating a Google Cloud CDN pointing to the bucket (example.com).

The CDN's load balancer should have a static IP address that you can use as an A record for @.

aeharding
  • 341
  • 1
  • 3
  • 10
0

You can't host your root domain from google cloud storage as of now, due to the cname restriction in DNS. You will have to have alias record in DNS pointing to an ipaddress to serve the root domain.

Firebase seems to be an alternate ideal option for this and is also almost free for standard traffic. Also has very few steps to host a static site - installing firebase cli with npm and a couple of commands to deploy. You can then get a list of ips from the firebase console that you can connect to your domain, by adding them in a alias record in your DNS.

https://firebase.google.com/docs/hosting

-2

Yes, this is possible and is documented here: https://developers.google.com/storage/docs/website-configuration

Basically, you need to set up a CNAME redirect to c.storage.googleapis.com

Jason Hall
  • 19,881
  • 4
  • 47
  • 56
  • 1
    CNAME lets you bind a subdomain to a bucket. So, I could do static.mydomain.com, for example. S3 offers the ability to bind a top-level domain to a bucket, afaik Google does not offer it. – rossmckegney Jan 02 '14 at 15:51
  • You can setup 'www' as the subdomain and use a CNAME record to redirect that to c.storage.googleapis.com. In addition, configure your DNS such that naked domains redirect to the www subdomain. I believe that achieves what you're after. – Niels Feb 14 '14 at 10:25