23 Jan 2018

How to host static site by Google Cloud Storage

Some of our front-end projects are hosted by Google Cloud Storage, and cached by Cloudflare. Today I will introduce how to host with GCS and Cloudflare.


1. Verify your domain

I like verifying by Domain Name provider because no need to host servers and really easy.

  1. Go Webmaster Central
  2. Click “ADD A PROPERTY”
  3. Choose “Alternative methods”
  4. Choose “Domain name provider”
  5. Type: TXT, Name : @, Content: google-site in Cloudflare
  6. Click “VERIFY”

This DNS record must not be deleted if you want to keep the verification.

2. Create Storage Bucket

  1. Create Bucket : gsutil mb gs://www.example.com, if you host https://www.example.com
  2. Upload files : gsutil rsync -R /path/to/dir gs://www.example.com
  3. chmod your files : gsutil acl -r ch -u AllUsers:R gs://www.example.com/*
  4. Set index/error pages : gsutil web set -m index.html -e 404.html gs://www.example.com

3. Add CNAME Record

  1. Create a CNAME record that points to c.storage.googleapis.com


It’s very easy to host static files.