6

I'm playing with GCP Load Balancing and want to redirect HTTP to HTTPS links. But cannot figure out.

My Load Balancing looks like:

Load balancer name
Front End:
  Protocols     IP             Certificate
  HTTP          x.x.x.x:80     -
  HTTPS         x.x.x.x:443    example-com

Back End: 
  Hosts          Paths        Backend
  example.com    /*           webs-backend

My webs backend is a simple nginx web server that listens on TCP/80 port. Nginx server configs:

server {
  server_name example.com;
  root /var/www/html;

  <snip>
}

Now with this GCP Load Balancing setup, I can access both HTTP and HTTPS, tried to configure Nginx to send cleints 301 redirect to HTTPS and it won't work. Too many redirects.

Question is, how can I configure GCP Load Balancing to redirect HTTP to HTTPS properly?

Ng Nam
  • 61
  • 1
  • 1
  • 2
  • possible duplicate - https://serverfault.com/questions/733166/redirect-all-http-traffic-to-https-when-using-the-https-load-balancer-on-googl – Daniel t. Jul 20 '17 at 04:32

2 Answers2

6

There is feature request submitted to Google product engineering team to support it on GCP HTTP(s) load-balancer. You can track this on Google public issue tracker.

There is a thread discussing the same and in NGINX server you can accomplish the same by adding following string into nginx configuration file like this:

if ($http_x_forwarded_proto = "http") { 
  return 301 https://$host$request_uri; 
}

You can check this thread as well which may help you.

sajjadG
  • 133
  • 5
N Singh
  • 438
  • 3
  • 10
1

Currently, you can do it directly from HTTP(S) Load Balancing. Google Cloud released Rewrites and Redirects support (since April 2020).

See this article to learn how to setup:

More details about this feature: