0
votes

in my setup I have a DigitalOcean load balancer connected with only one droplet(for now) running nginx. I Manage my SSL certificate with the load balancer via SSL Termination. The Load Balancer has this forwarding rules set up:

HTTP on port 80 -> HTTP on port 80

HTTP2 on port 443 -> HTTP on port 80

There is an option for the load Balancer to Redirect HTTP to HTTPS. But if I use this option it uses an 307 redirect instead of an 301. According to DigitalOcean this is intended. I was told for Seo reasons it should be using a 301. I tried to disable the option and redirect using nginx configs but i ended up in a infinity loop. This is the snipped i used:

server {
        listen 80;
        server_name _;
        # $scheme will get the http protocol
        # and 301 is best practice for tablet, phone, desktop and seo
        return 301 https://$host$request_uri;
}

Does anyone know how to properly handle this situation? Any help would be greatly appreciated.

Cheers Raph

1

1 Answers

1
votes

I actually figured it out i could prevent the loop with adding

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

as suggested in this post