Spring boot ELB Nginx将http重定向到https

Spring boot ELB Nginx将http重定向到https,spring-boot,nginx,amazon-elb,Spring Boot,Nginx,Amazon Elb,这是我的配置: server { listen 80; server_name *.example.com; if ($http_x_forwarded_proto = 'http') { return 301 https://$server_name$request_uri; } } 当我转到example.com nginx时,将我重定向到,但页面是存根nginx index.

这是我的配置:

server {
      listen         80;
      server_name    *.example.com;
      if ($http_x_forwarded_proto = 'http') {            
        return 301 https://$server_name$request_uri;
        }
}
当我转到example.com nginx时,将我重定向到,但页面是存根nginx index.html。 如果我去www.example.com,它将保持不安全状态,因此根本不会重定向

我做错了什么? 谢谢

编辑: 当我喜欢这篇文章时:

返回301 https://$server\u name$request\u uri$http\u x\u forwarded\u proto

然后它被重定向
当然,它是404,因为http端点是愚蠢的。

您确实应该避免在nginx中使用“if”,因为它是性能杀手

您应该只使用以下选项:

server {
  listen      80;
  server_name *.example.com;

  ## redirect http to https ##
  return 301 https://example.com$request_uri;
}
并定义“example.com”服务器


如果elb正确设置为向example.com发送443请求,并且example.com:443上有侦听套接字,则一切正常。

谢谢@requirem13。我试了你的建议,但没有成功。我构建了一个spring boot应用程序,可以监听第80个端口。然后ELB被设置为在443和80上监听,并重定向到运行我的spring boot应用程序的机器的80。你有什么想法吗?也许我弄错了什么?不幸的是,这不是有用的答案,因为这个解决方案导致无限循环。亚马逊解释说,在那篇文章中,我附加了最初的问题。我也尝试过这个解决方案。这也不管用。