I’m setting up my load balancer in GCP with 2 nodes (Apache httpd), with domain lblb.tonegroup.net.
Currently my load balancer is working fine, the traffic is switching over between the 2 nodes, but how do i configure to redirect http://lblb.tonegroup.net to https://lblb.tonegroup.net ?
Is it possible to configure it at the load balancer level or I need to configure it at apache level? I have Google Managed SSL cert installed FYI.
7
Answers
It is not possible to do that directly on GCP Load balancer.
One possibility is to make the redirection on your backend service. GCP Loader balancer add
x-forwarded-proto
property in requests headers which is equal to http or https. You could add a condition based on this property to make a redirection.I believe the previous answer provided by Alexandre is correct; currently, it’s not possible to redirect all HTTP traffic to HTTPS when using the HTTP(S) Load Balancer. I have found a feature request already submitted for this feature; you can access it and add your comment using this link.
You have also mentioned you are using Google managed SSL certificate but the only workaround I found is to redirect it in the Server level. In such scenario, you would have to use self-managed SSL certificate.
To redirect HTTP URLs to HTTPS, do the following in Apache server:
You would have to configure an Apache server configuration file. Refer to the apache.org documentation on Simple Redirection for more details.
Maybe it’s too late, but I had the same problem and here my solution:
{tls_version}
asX-SSL-Protocol
custom header.X-SSL-Protocol
value:You can check the header value on your web server or from an intermediate load balancer VM instance. My case with HAProxy:
Right now the redirection from http to https is possible with the Load Balancer’s Traffic Management.
Below is an example of how to set it up on their documentation:
https://cloud.google.com/load-balancing/docs/https/setting-up-traffic-management#console
Basically you will create two of each “forwarding rules”, targetproxy and urlmap.
2 URLMaps
httpsRedirect: true
redirectResponseCode: FOUND
2 forwarding rules
2 targetproxy
targetHttpProxy
, this will where the 1st forwarding rule is forwarded to and is mapped to the 1st URLMaptargetHttpsProxy
where the 2nd forwarding rule is forwarded to and is mapped to the 2nd URLMap========================================================================
Below is a Cloud Deployment Manager example with Managed Certificates and Storage Buckets as the backend
storagebuckets-template.jinja
backendbuckets-template.jinja
ipaddresses-template.jinja
sslcertificates-template.jinja
loadbalancer-template.jinja
httpproxies-template.jinja
templates-bundle.yaml
$ gcloud deployment-manager deployments create infrastructure --config=templates-bundle.yaml > output
command output
If you use Terraform (highly recommend for GCP configuration), here’s a sample config. This code creates two IP addresses (v4 & v6) — which you would use in your https forwarding rules as well.
At a high level, to redirect HTTP traffic to HTTPS, you must do the following:
Please check:
https://cloud.google.com/load-balancing/docs/https/setting-up-http-https-redirect
Perhaps I’m late to the game but I use the following:
[ingress.yaml]:
[redirect-frontend-config.yaml]
I’m using the default "301 Moved Permanently", but if you’d like to use something else, just add a row under redirectToHttps containing
MOVED_PERMANENTLY_DEFAULT to return a 301 redirect response code (default).
FOUND to return a 302 redirect response code.
SEE_OTHER to return a 303 redirect response code.
TEMPORARY_REDIRECT to return a 307 redirect response code.
PERMANENT_REDIRECT to return a 308 redirect response code.
Further reading at
https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-features
https://cloud.google.com/kubernetes-engine/docs/concepts/ingress