0

My goal is to have a redirect http-to-https for a loadbalancer for 3 instance groups on Google Cloud Platform.

I have one load-balancer http-to-https which redirects to another load-balancer for my 3 applications (3 backend services, 3 instance groups). I followed documentation, it works great for only 1 of those banckend-services, the ones which is default.The other 2 backends are not redirected to https when I curl the backend

Load-balancer-http-to-https settings

Instance-group Load-balancer
not shown here, but IPs in both loadbalancers match

When I curl https://domain1.fr -> OK
When I curl http://domain1.fr -> 301 redirect to https -> OK

When I curl https://domain2.fr -> OK
When I curl http://domain2.fr -> OK (but no redirect to https)

When I curl https://domain3.fr -> OK
When I curl http://domain3.fr -> OK (but no redirect to https)

Not shown here, but if I change default backend to backend2 in my LoadBalancer, it redirects to https for domain2.fr.

1 Answer 1

1

You will have to add extra host and path rules to redirect http to https based on specific domain. This can be done in the google cloud console UI or using gcloud sdk.

  1. In the UI,you can edit the LB and add a "new host and path rule", and set "Hosts" and "Host redirect" to your domain. Do this for each domain.

  2. Using gcloud, you can export the URL map, modify the contents as below and upload it.

a. export existing url map -

gcloud compute url-maps export YOUR-URL-MAP --destination=/tmp/urlmap.yaml

The original yaml file will look like this for a single domain redirection web1.example.net -

name: webmap kind: compute#urlMap defaultUrlRedirect: hostRedirect: web1.example.net httpsRedirect: true redirectResponseCode: MOVED_PERMANENTLY_DEFAULT stripQuery: false 

Add the second domain you want to redirect - in this case it is web2.example.net. Note the hostRules and pathMatchers section. You can add extra host rule and pathMatcher for each domain -

name: webmap kind: compute#urlMap defaultUrlRedirect: hostRedirect: web1.example.net httpsRedirect: true redirectResponseCode: MOVED_PERMANENTLY_DEFAULT stripQuery: false hostRules: - hosts: - web2.example.net pathMatcher: path-matcher-1 pathMatchers: - defaultUrlRedirect: hostRedirect: web2.example.net httpsRedirect: true redirectResponseCode: MOVED_PERMANENTLY_DEFAULT stripQuery: false name: path-matcher-1 

You can import this file -

gcloud compute url-maps import YOUR-URL-MAP --source=/tmp/urlmap.yaml

It will take a few minutes for the change to take effect.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.