繁体   English   中英

将 http 重定向到 https AWS 应用程序负载均衡器

[英]Redirect http to https AWS Application Load Balancer

大家好,所以我将我的 ELB 配置为使用 SSL 证书并且效果很好,但是,我仍然有一个问题,如果用户通过 HTTP 下的端口 80 访问我的网站,该网站不会将他们重定向到 HTTPS 安全连接。 这是我在 Elastic Beanstalk 配置选项卡中看到的 ELB 配置的屏幕截图。 感谢您的帮助,谢谢。 elb配置

根本不是 elb,我只需添加以下代码:

if (process.env.NODE_ENV === "production" || process.env.NODE_ENV === "awsDevelopmentServer") {
  app.use(function(req, res, next) {
    // Insecure request?
    if (req.get("x-forwarded-proto") == "http") {
      // Redirect to https://
      return res.redirect("https://" + req.get("host") + req.url);
    }```

虽然您似乎可以通过在应用程序中进行重定向来使其正常工作,但可以完全在 ALB 中执行此重定向。 文档: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html

此功能于 2018 年 7 月发布。https://aws.amazon.com/about-aws/whats-new/2018/07/elastic-load-balancing-announces-support-for-redirects-and-fixed-responses-用于应用程序负载平衡器/

Elastic Beanstalk 可能没有推出自己的支持来配置它。 您也许可以通过 ebextensions 对其进行配置,但目前最好只在您的应用程序中进行配置。

您可以通过以下方式设置 Application Load Balancer 侦听器:

HTTP 80: default action 
IF 
Requests otherwise not routed
THEN 
Redirect to HTTPS://#{host}:443/#{path}?#{query}
Status code:HTTP_301

事实上,你不能再从 elastic beanstalk 的界面上做到这一点 不要从应用程序中做到这一点,负载解决方案不好。 您现在必须 go 到 EC2 负载均衡器并按照此处所述更改端口 80 的侦听器: https://medium.com/@j_cunanan05/how-to-redirect-http-to-https-in-amazon-web-services -aws-弹性-beanstalk-67f309734e81

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM