Notes on Hosting a Static Site in a Google Cloud Provider Storage Bucket

Static sites are great and hosting them in simple storage buckets like S3 or GCP Storage is cheap and easy. I've been drawn to GCP lately because the docmentation and tools are often simpler than AWS. However, GCP does have a few caveats for hosting static sites.

Looks look at the setup first. Once you've installed GCP's command line tool gsutil the quickest documentation for setting up a static site actually comes from the gsutil web --help command.

For example, suppose your company's Domain name is You could set up a website bucket as follows:

  1. Create a bucket called (see the "DOMAIN NAMED BUCKETS"
     section of "gsutil help naming" for details about creating such buckets).

  2. Create index.html and 404.html files and upload them to the bucket.

  3. Configure the bucket to have website behavior using the command:

       gsutil web set -m index.html -e 404.html gs://

  4. Add a DNS CNAME record for pointing to
     (ask your DNS administrator for help with this).

Full instructions can be found in the GCP documentation.

And now for the caveats:

You can't host without a subdomain

Since you're creating a CNAME, you can't serve your site at There is no easy way to get around this. The best path forward is to use your registrar to forward to

Single Page Apps will 404 on pages that don't exist

Step 3 in the above directions configures your bucket to use index.html as your MainPageSuffix. This means, the use won't see index.html as the last part of the URI.

If you're building a single page app, you probably want all urls to redirect to your index page so you can route on the client. To do this, you'd run the web command as:

gsutil web set -m index.html -e index.html gs://

This works, but it unfortunately still returns a 404 response to the client. To the human on the other end, this doesn't matter, but to clients it may.