0

I have a load balancer (LB) in GCP that is currently redirecting some matching paths to an external (non-GCP) service (301 Redirect). I am trying to add additional set of prefixMatch rules that will instead act as a reverse proxy to a separate 3rd party service (WebFlow, in case it matters).

I have a backend service (external) that uses an NEG that points to the fully qualified domain of the 3rd party host [mysite.webflow.io]. I have the rules set up to use that service for 2 paths (/blog/, /pages/).

After updating the LB routing rules with the following YAML, the priority 1 rules are still working, but the priority 2 rules (the proxy) are pointing to the 404 page found in my default service.

Hosts: mysite.com, www.mysite.com

defaultService: projects/my-gcp-project-1/global/backendServices/my-default-service
name: redirect-rules
routeRules:
- urlRedirect:
    hostRedirect: subdomain.mysite.com
    redirectResponseCode: MOVED_PERMANENTLY_DEFAULT
  matchRules:
  - prefixMatch: /rad-page-1
  - prefixMatch: /rad-page-2
  priority: 1
- matchRules:
  - prefixMatch: /pages/*
  - prefixMatch: /blog/*
  priority: 2
  routeAction:
    weightedBackendServices:
    - backendService: projects/my-gcp-project-1/global/backendServices/proxy-backend-service
      weight: 100
    urlRewrite:
      hostRewrite: www.mysite.com

I'm wondering if I'm missing something like preserveHost: true?

I'm new to setting up rules like this in GCP. Thanks in advance for the help!

1

1 Answer 1

0

This setting preserveHost: true is crucial when you want to use a Google Cloud Load Balancer to reverse proxy or rewrite URLs, but only modify the host portion; the original path remains unchanged.

A URL rewrite separates a URL from a resource. You can translate from human-friendly URLs, which are easier for users to remember and use, transforming them into search-engine friendly URLs, which are easier for search engines to find, or into internal implementation-specific URLs.

The URL rewrite feature does the following:

1.Read the incoming URL in the request.

2.Replaces the host, the path, or both the host and the path, transforming the URL before directing traffic to the backend service or backend bucket.

Refer to the official GCP document on Set up URL rewrite for a classic Application Load Balancer and also refer to the official GCP document on URL maps for matching the paths.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.