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?