Cloud load balancer - Add host name of proxied backend domain in the urlMap

Hello,

I have configured weighted two backend services for an URL. However all are returning 404. Looks like proxied request contains the hostname of the original request, not the FQDN for which the request is proxied ? How can I achieve this, any alternatives ? Below is my detailed setup. Any help is much appreciated.

Setup

I have an internet backend mirrored on two internet backends eg https://domain.a/api and https://domain.b/api. I have created two backend services for each backend as internet backend service allows only one internet NEG. I have created application load balancer on domain eg api.app and used weighted backend services to direct traffic for each internet backend services.

When I invoke api.app/anyendpoint it is giving 404 as proxied request contains the host name as api.app not the internet backend domain domain.a or domain.b which was selected by the envoy.

When I hard code the host using hostRewrite option in urlRewrite of URLMap it is invoking hardcoded backend. How can I send the respective host name in the proxied request which should be the one which is selected by the envoy?

Below is sample URLMAP

defaultService: projects/<project>/global/backendServices/backend-service-a
name: match-url-shortner
routeRules:
- matchRules:
  - prefixMatch: /anyendpoint
  priority: 2
  routeAction:
    weightedBackendServices:
    - backendService: projects/<project>/global/backendServices/backend-service-a
      weight: 50
    - backendService: projects/<project>/global/backendServices/backend-service-b
      weight: 50
    urlRewrite:
      pathPrefixRewrite: /api/anyendpoint
      hostRewrite: ?
1 Like

I’m able to get host name using headerAction work around in the weightedBackendServices to add replace host name with the bckend service like below. But this may not work when multiple internet NEG are supported in a internet backend end service.

defaultService: projects/<project>/global/backendServices/backend-service-a
name: match-url-shortner
routeRules:
- matchRules:
  - prefixMatch: /anyendpoint
  priority: 2
  routeAction:
    weightedBackendServices:
    - backendService: projects/<project>/global/backendServices/backend-service-a
      weight: 50
      headerAction:
        requestHeadersToAdd:
        - headerName: host
          headerValue: backend-host-a.com
          replace: true
    - backendService: projects/<project>/global/backendServices/backend-service-b
      weight: 50
      headerAction:
        requestHeadersToAdd:
        - headerName: host
          headerValue: backend-host-b.com
          replace: true
    urlRewrite:
      pathPrefixRewrite: /api/anyendpoint
      hostRewrite: ?
1 Like