ELB Nginx 将 http 重定向到 https
Posted
技术标签:
【中文标题】ELB Nginx 将 http 重定向到 https【英文标题】:ELB Nginx redirect http to https 【发布时间】:2018-08-18 02:05:34 【问题描述】:这是我的配置:
server
listen 80;
server_name *.example.com;
if ($http_x_forwarded_proto = 'http')
return 301 https://$server_name$request_uri;
当我转到 example.com 时,nginx 将我重定向到 https://example.com,但该页面是一个存根 nginx index.html。 如果我去 www.example.com 它保持不安全,所以它根本不会被重定向。
我做错了什么? 谢谢。
编辑: 当我喜欢这篇文章时:https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/
返回 301 https://$server_name$request_uri$http_x_forwarded_proto;
然后重定向https://example.com/http 当然是 404,因为 http 端点很愚蠢。
【问题讨论】:
我也试过这个解决方案。它也不起作用。 allcloud.io/how-to-force-https-behind-aws-elb 【参考方案1】:你真的应该避免在 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 上有一个监听套接字,那就没问题了。
【讨论】:
谢谢@Requiem13。我尝试了你的建议,但没有运气。我构建了一个监听第 80 个端口的 spring boot 应用程序。然后 ELB 设置为同时监听 443 和 80 并重定向到运行我的 spring boot 应用程序的 80 台机器。你有什么想法?也许我配置错误?谢谢。 不幸的是,这不是有用的答案,因为此解决方案会导致无限循环。亚马逊解释说,在那篇文章中我附上了最初的问题。以上是关于ELB Nginx 将 http 重定向到 https的主要内容,如果未能解决你的问题,请参考以下文章
ELB 后面的 Symfony2 重定向到 http 而不是 https
没有 index.php 的 AWS ELB 将 HTTP 重定向到 HTTPS
如何为 AWS Elb 后面的 reactJs SPA 重定向 http 到 https?
如何在 ELB 应用程序负载均衡器上将 HTTPS 重定向到 HTTP