1

We want to map subdomains to static sites hosted in folders within a GCP bucket. From a non-technical perspective, this is identical to what Shopify and other website builders do with their sites for trial customers.

For example:

1. Navigate to foo.rootdomain.com
2. Display site stored inside at <Shared Google Bucket>/foo/index.html
3. Continue displaying foo.rootdomain.com in URL address bar

These subdomains/subdirectories will be created on-demand programatically when customers request them. For example, a customer could request "baz.rootdomain.com", and then we will upload their static site to the shared Google bucket's /baz subdirectory. These subdomains should all be SSL'd. We should be able to support tens to hundreds of thousands of these subdomains, all on the same root domain. That is:

abc.rootdomain.com --> <Shared Google Bucket>/abc/index.html
anothersubdomain.rootdomain.com --> <Shared Google Bucket>/anothersubdomain/index.html
foobar.rootdomain.com --> <Shared Google Bucket>/foobar/index.html
<ANY_TEXT>.rootdomain.com --> <Shared Google Bucket>/<ANY_TEXT>/index.html

I started by looking into Google's load balancers and URL maps to handle these, but AFAICT, these can only map to explicit resources rather - so they could be mapped to a backend bucket which redirects to a specific bucket, but couldn't be mapped to a parameterized bucket based on the subdomain. This SO answer explains how to map wildcard routes to specific resources, which doesn't work for this use-case.

I also looked into hosting a service at Google's App Engine and doing routing via dispatch.yaml because subdomains need to be listed out explicitly and there is a limit of 20 routing rules, so we'd need to keep creating them for every 20 subdomains, which wouldn't scale.

It looks like in this question the author had the same problem and was able to solve it by "creating separated VM instance that actually proxying requests to the google bucket". I looked up 'GCP vm proxy requests to google bucket' and wasn't able to figure out what this means, or how to do it. This doc page talks about using proxies to keep files private, which isn't what we're trying to do, and was very confusing to read through in general.

How can we approach this issue?

  • Select a different service. Google Cloud Storage does not provide processing power, URL rewrites, custom domain maps, etc. Use a traditional website on a virtual machine (Apache/Nginx) that supports rewriting URLs, wildcard domains, etc. Otherwise, select a hosting service with the features you require. – John Hanley Feb 07 '22 at 04:19
  • You must remove the folder in the bucket. Create one bucket per each subdomain. You can also deploy your static file on AppEngine if you want, but the deployment mode is different. – guillaume blaquiere Feb 07 '22 at 09:22
  • @guillaumeblaquiere Approach 1 was to create one bucket per each subdomain, until I realized that there is a quota limit of 3 Backend Buckets. Approach 2 was to config a routing rule for each subdomain. For some reason, when you create a Host 2 of foo.rootdomain.com and a path of /foo/*, it creates an additional Host 3 of foo.rootdomain.com with a path of /*. So, when I navigate to foo.rootdomain.com, it redirects to Host 1: `(Default) Unmatched host and path...`. Approach 3: Advanced host and path rule (YAML editor), but the specified `pathRedirect: "/foo"` leads to: ERR_TOO_MANY_REDIRECTS. – datalifenyc Jan 01 '23 at 01:26

0 Answers0