Murcielago
Murcielago

Reputation: 1192

Google cloud load balancer redirect www to naked domain

I'm using Google Cloud Load Balancer as the ingress controller to my GCP Kubernetes application. I want all requests to www.my_domain.com to be redirected to my_domain_.com.

Note: My GCLB is configured with an SSL certificate that is valid for both www.my_domain.com and my_domain.com.

I know this is possible using an http redirect in my external DNS management console, but an issue arises because of SSL termination.

  1. I create an http redirect rule in my DNS management console to route all www.my_domain.com traffic to https://my_domain.com.

  2. If a client browses to domain https://www.my_domain.com, they will get a browser warning because the request will first go to server of my DNS management tool, which is not configured with a matching SSL cert.

I know that GCLB has limitations for redirecting http traffic to https, but that's not my main concern here. What I want to know is if it's possible in GCLB to configure a routing rule so that any request for www.my_domain.com is redirected to my_domain.com.

Thanks for any help!

Upvotes: 6

Views: 2077

Answers (2)

Jerome
Jerome

Reputation: 146

Redirect rules are supported when you switch your "Host and path rules" from the "Simple host and path rule" to the "Advanced host and path rule" option now. This advanced option allows for URL redirect and URL rewrite.

Edit your Load Balancer, go to "Host and path rules", click "Add host and path rule".

Host: www.my_domain.com

Path: /*

Action: Redirect the client to different host/path and specify your host my_domain.com

Path redirect: Full path redirect

Redirect response code: 301

HTTPS redirect: Enable

Check this Google Cloud page (no screenshots unfortunately) here https://cloud.google.com/load-balancing/docs/https/setting-up-url-redirects-classic

Upvotes: 2

Akar
Akar

Reputation: 584

Unfortunately, there is no such functionality in GCLB.

In this case, you should use custom (for example nginx) ingress controller.

You can find here and here how to setup nginx controller for Kubernetes.

Upvotes: 0

Related Questions