How to host static site by Google Cloud Storage
By: Tomoya Amachi
Posted: Feb 23, 2018
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.
Steps
1. Verify your domain
I like verifying by Domain Name provider because no need to host servers and really easy.
- Go Webmaster Central
- Click "ADD A PROPERTY"
- Choose "Alternative methods"
- Choose "Domain name provider"
- Type: TXT, Name : @, Content: google-site in Cloudflare
- Click "VERIFY"
This DNS record must not be deleted if you want to keep the verification.
2. Create Storage Bucket
- Create Bucket : gsutil mb gs://www.example.com, if you host https://www.example.com
- Upload files : gsutil rsync -R /path/to/dir gs://www.example.com
- chmod your files : gsutil acl -r ch -u AllUsers:R gs://www.example.com/*
- Set index/error pages : gsutil web set -m index.html -e 404.html gs://www.example.com
3. Add CNAME Record
- Create a CNAME record that points to c.storage.googleapis.com
Conclusion
It's very easy to host static files.