2

I can't find a way to set up Google's Cloud Storage load balancer's host path and rules to point different domains to their corresponding folders in a single bucket.

I have two domains: foo.com and bar.com and I have a bucket with two folders in it: foo/ and bar/. I want foo.com to serve files from the foo/ folder and bar.com to serve files from the bar/ folder.

I only see options to point specific domain paths to different buckets (e.g. foo.com/bar/ pointing to another bucket) but not different hosts/domains to different paths in bucket. How can I set up the rules to achieve this?

MarshallBananas
  • 129
  • 1
  • 10

1 Answers1

1

You need to use the advance feature of HTTPS load balancer and especially the URL prefix rewrite.

For that, you need to configure your host and path rules in advanced mode. Then, for the default access (without specific domains), you can redirect (URL REWRITE) to the /default folder of the backend.

enter image description here

Add host and path, and for foo.com, redirect to the folder /foo by rewriting the prefix

enter image description here

Do the same for bar.

Wait 5 minutes (let the Load Balancer to advertise the POP), and enjoy :)

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Thank you! It works exactly as required but only with the trailing slash. When I go to foo.com/folder (without the trailing slash) it redirects me (301) to foo.com/foo.com/index.html which does not exist. Which is contrary to the default behavior described in the docs with MainPageSuffix enabled: https://cloud.google.com/storage/docs/static-website#examples (no zero byte objects). – MarshallBananas Jul 10 '21 at 04:37