I’m working with a GCP application load balancer that has two different backends configured. My setup should route most traffic to the primary backend, but I need all requests going to /login/*
to be handled by my authentication backend instead.
I’ve tried different URL mapping configurations but can’t get the routing to work correctly. Here’s what I’m seeing:
Incoming URL | Should go to | Expected path | Actually goes to | Actual path |
---|---|---|---|---|
mydomain.com | primary-backend | mydomain.com | auth-backend | '' |
mydomain.com/ | primary-backend | mydomain.com/ | auth-backend | '' |
mydomain.com/test | primary-backend | mydomain.com/test | auth-backend | '' |
mydomain.com/login/verify | auth-backend | mydomain.com/verify | auth-backend | mydomain.com/login/verify |
My current URL map looks like this:
defaultService: https://www.googleapis.com/compute/v1/projects/my-app/global/backendServices/primary-backend
hostRules:
- hosts: [mydomain.com, '*.mydomain.com']
pathMatcher: main-matcher
name: app-urlmap
pathMatchers:
- defaultService: https://www.googleapis.com/compute/v1/projects/my-app/global/backendServices/primary-backend
name: main-matcher
routeRules:
- matchRules:
- pathTemplateMatch: /login/{route=**}
priority: 1
service: https://www.googleapis.com/compute/v1/projects/my-app/global/backendBuckets/auth-backend
routeAction:
urlRewrite:
pathTemplateRewrite: /{route}
When I run the validation, most requests are going to the wrong backend and the URL rewriting isn’t working as expected. What could be causing this routing problem?