I'm using L7 HTTP Load Balancer. I want to redirect from HTTP requests to HTTPS. This is the part of my nginx config. It works when I access to my web server without Load Balancer. But it does not work with Load Balancer. 404 error is returned.
How can I fix it?
I'm using nginx
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
...
}
HTTP Response
HTTP/1.1 404 Not Found
Server: Google Frontend
I found this issue below and I added $http_x_forwarded_proto check. But the result did not change.
Issue 255: Redirect all HTTP traffic to HTTPS when using the HTTP(S) Load Balancer https://code.google.com/p/google-compute-engine/issues/detail?id=255&thanks=255&ts=1446612833
server {
listen 80;
server_name example.com;
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
...
}
Update 1
I found that my load balancer has only HTTPS protocol end-point config. I think I need HTTP port end-point setting.
This post below would be helpful.