3
votes

I’m trying to set up HTTPS with the help of Google load balancer. I created instance group, front ends, backends, health checker and the actual load balancer. I set up two Frontends one for HTTP on port 80 and HTTPS on port 443. They have different IP-s respectively.

I then pointed my DNS to the HTTPS (443) version of my IP.

It works great when I point my browser directly to https://example.com

However, when I use nonsecure protocol, I want to redirect the user to secure connection. After some reading, I learned that the only way to do this is directly from my node.js app (or nginx). what I do is check if req.headers['x-forwarded-proto'] is false and redirect to 'https://' + global.config.hostname + req.url

global.config.hostname is set to example.com

primoz@static-server[master]$ wget http://example.com
--2017-08-30 10:13:12--  http://example.com/
Resolving example.com... 35.196.241.151
Connecting to example.com|35.196.241.151|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-08-30 10:13:12 ERROR 404: Not Found.

35.196.241.151 is example of HTTPS IP from my load balancer set up listening on port 443.

It looks to me that the redirect is trying to access my secure HTTPS IP over port 80 and it’s not accessible.

What am I missing here?

1

1 Answers

7
votes

This is what I found out.

It's a common problem a lot of people have, take a look at this issue thread where people are requesting an easier way to set this up.

https://issuetracker.google.com/issues/35904733

I fixed this by setting up static IP instead of the ephemeral IP for HTTP and HTTPS frontends. This way they both have the same IP and the redirect inside your node app or nginx works as it should.