logo

How To Host Static Websites On GCP Cloud Storage

Last Updated: 2023-10-21

Follow the install page to install gsutil: https://cloud.google.com/storage/docs/gsutil_install

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

To sync the local public folder to the cloud:

$ gsutil -m rsync -d -r public gs://www.yourdomain.com

gsutil options:

  • -m: perform parallel (multi-threaded/multi-processing) synchronization.

rsync options:

  • -d: "Delete extra files under dst_url not found under src_url."
  • -r: recursive.

DNS

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

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

Error: Access Denied.

Add a new permission in PERMISSIONS tab:

  • Principle = allUsers
  • Role = Storage Object Viewer