I'm having a hard time trying to figure out how to achieve the routing/rewriting rules I need for the application I'm trying to set up and would be very grateful for any assistance.
I have a simple web app running on three Cloud Compute VM Instance Groups. The app is running fine on each VM (single VM per instance group). The app is identical apart from a small detail in the HTML which identifies the instance.
The Load Balancer is working fine in terms of routing traffic to the instances as such using paths, but I need to provide each user of the app a unique URL. What I would really like to achieve is something like this:
Url Path | Routes to | Instance Group |
---|---|---|
/bronze/summary | /summary | 1 |
/silver/summary | /summary | 2 |
/gold/summary | /summary | 3 |
This way each user hits their own URL path and the LB routes the request to /summary on the specific instance group which is running that user's version of the app.
I cannot see how to set this up using the basic host and path rule view. Using the advanced host and path rule view seems to offer more possibilities and I found this resource: https://cloud.google.com/load-balancing/docs/https/setting-up-url-rewrite
But, I'm not sure how to write the rules. What does not help from the example given in the link is that the target used is storage not instance groups (VMs) and I have no idea how to translate that example.
My current paths and rules file looks like this:
defaultService: projects/<project-name>/regions/europe-west2/backendServices/backend-1
name: path-matcher-1
pathRules:
- paths:
- /summary
service: projects/<project-name>/regions/europe-west2/backendServices/backend-1
- paths:
- /bronze/summary
service: projects/<project-name>/regions/europe-west2/backendServices/backend-1
- paths:
- /silver/summary
service: projects/<project-name>/regions/europe-west2/backendServices/backend-2
- paths:
- /gold/summary
service: projects/<project-name>/regions/europe-west2/backendServices/backend-3
But I cannot see how to remove the '/bronze' segment in the path prior to routing. I think if I had a route on the web app like '/bronze/summary' then it would work, but that would be a giant pain to implement.
Can someone guide me in the right direction, please?
THANKS!!
UPDATE
After a lot of messing about and struggling with the documentation, I came up with this:
defaultService: projects/<project-name>/regions/europe-west2/backendServices/backend-1
name: path-matcher-1
pathRules:
- paths:
- /bronze/*
service: projects/<project-name>/regions/europe-west2/backendServices/backend-1
routeAction:
urlRewrite:
pathPrefixRewrite: /
- paths:
- /silver/*
service: projects/<project-name>regions/europe-west2/backendServices/backend-2
routeAction:
urlRewrite:
pathPrefixRewrite: /
- paths:
- /gold/*
service: projects/<project-name>/regions/europe-west2/backendServices/backend-3
routeAction:
urlRewrite:
pathPrefixRewrite: /
It seems to do what I need.
All I do now, is clone down the template app and as part of the local build and run (on the VM itself), I'm updating the Navigation partial to prefix with '/bronze/', '/silver/' or '/gold/' and it all seems to be working fine.
Got to say the documentation on this is quite hard going for a newbie, could do with a lot more simple examples.
Hopefully this may be useful to someone.