4
votes

Currently we have below requirement:

Each user can have their own subdomain and folder under the Google Storage Bucket with content that should be served via this subdomain, for example:

[domain] user1.example.com -> [bucket] example.com/user1/index.html
[domain] user2.example.com -> [bucket] example.com/user2/index.html

So bucket having below structure:

 - [Bucket] example.com
     - [Folder] user1
       - [File] Index.html
     - [Folder] user2
       - [File] Index.html
     - etc..

Subdomains will be added dynamically and I can't just set Map Rules (can update it via API, but I guess they have limits for Map Rules).

Also those HTML content should be served via HTTPS.

I have setup domain, storage bucket, load balancer on GCP but currently stuck with URL/Path rewriting on LoadBalancer.

So the question - is it possible to make a call to the "user1.example.com" and via Load Balancer serve HTML connect from the bucket "/example.com/user1" folder?

Is it possible to make it work with above architecture or it will require individual buckets for each user or it will only work with separated Reverse Proxy that will redirect the trafic to specific folder/domain?

Thanks.

1

1 Answers

0
votes

As you have identified, there is no generic way to map the host name to part of the path. You could have a separate hostRules entries for each subdomain, but that limits at 50 entries. You could create whole new forwarding rule & target http proxy for every 50 subdomains you have. which will scale up but is still complex.

Alternatively, you could point to a backend service of instances running a proxy like Envoy or HAProxy. These have powerful rewriting that can do this.