logo

How To Host Static Websites On GCP Cloud Storage

Last Updated: 2024-04-19

Install CLI

Follow the install page to install gdcloud CLI: https://cloud.google.com/sdk/docs/install (the previous version of this guide was using gsutil, but the preferred way is to use gdcloud storage instead).

Follow the official guide

Follow the tutorial to setup: https://cloud.google.com/storage/docs/hosting-static-website

Basically create a bucket named after your website like www.yourdomain.com, and verify ownership by creating a new property in the Search Console.

Upload static files to your bucket

To sync the local out folder to the cloud:

$ gcloud storage cp -r out/* gs://www.yourdomain.com

Setup DNS

Go to the website where you registered the domain. (e.g. CloudFlare)

Set a CNAME and point it to c.storage.googleapis.com

NAME                  TYPE     DATA
www                  CNAME    c.storage.googleapis.com.

Troubleshooting: "Error: Access Denied"

Remember to add a new permission in PERMISSIONS tab:

  • Principle = allUsers
  • Role = Storage Object Viewer