简体   繁体   English

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

[英]Redirect http to https AWS Application Load Balancer

Hey everyone so I configured my ELB to use an SSL certificate and it works great, however, I still have a problem where if a user comes to my website on port 80 under HTTP the website does not redirect them to an HTTPS secure connection.大家好,所以我将我的 ELB 配置为使用 SSL 证书并且效果很好,但是,我仍然有一个问题,如果用户通过 HTTP 下的端口 80 访问我的网站,该网站不会将他们重定向到 HTTPS 安全连接。 Heres a screenshot of my ELB configuration as seen in the Elastic Beanstalk configuration tab.这是我在 Elastic Beanstalk 配置选项卡中看到的 ELB 配置的屏幕截图。 Any help is appreciated thank you.感谢您的帮助,谢谢。 elb配置

It wasn't the elb at all I simply had to add this code:根本不是 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);
    }```

While it seems like you got it working by redirecting in your application, it is possible to do this redirect entirely in your ALB.虽然您似乎可以通过在应用程序中进行重定向来使其正常工作,但可以完全在 ALB 中执行此重定向。 Documentation: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html文档: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html

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

Elastic Beanstalk may not have launched their own support to configure this. Elastic Beanstalk 可能没有推出自己的支持来配置它。 You may be able to configure it via ebextensions, but for now it may be best to just do it in your application.您也许可以通过 ebextensions 对其进行配置,但目前最好只在您的应用程序中进行配置。

You can set up Application Load Balancer listener in the following way:您可以通过以下方式设置 Application Load Balancer 侦听器:

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

In fact, you cannot do it anynmore from the interface of elastic beanstalk Don't do it from the app, bad solution for load.事实上,你不能再从 elastic beanstalk 的界面上做到这一点 不要从应用程序中做到这一点,负载解决方案不好。 You must now go to the EC2 load balancer and change the listener for port 80 as described here: https://medium.com/@j_cunanan05/how-to-redirect-http-to-https-in-amazon-web-services-aws-elastic-beanstalk-67f309734e81您现在必须 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.

相关问题 使用 Application Load Balancer 将 http 重定向到 https - Redirect http to https using Application Load Balancer 是否有选项将 http 流量重定向到 aws.network 负载均衡器中的 https - Is there option to redirect http traffic to https in aws network load balancer 如何使用 GCP 负载均衡器将 HTTP 重定向到 HTTPS - How to redirect HTTP to HTTPS using GCP load balancer 负载均衡器无法在 Elastic Beanstalk 中从 HTTP 重定向到 HTTPS - Load Balancer unable to redirect from HTTP to HTTPS in Elastic Beanstalk Ingress 和 AWS 应用程序负载均衡器 - Ingress and AWS Application Load Balancer 指向经典负载均衡器的 AWS Route53 A 记录(由 Kube.netes 创建)适用于 http 但不适用于 https - AWS Route53 A-record pointing to classic load balancer (created by Kubernetes) works with http but not https Django 落后于 NGINX 反向代理和 AWS Application Load Balancer 未在 HTTP_X_FORWARDED_PROTO 中从客户端转发 HTTPS - Django behind NGINX reverse proxy and AWS Application Load Balancer doesn't get HTTPS forwarded from client in HTTP_X_FORWARDED_PROTO 负载均衡器中的 AWS 重定向以使用 POST 和 PUT - AWS redirect in Load Balancer to work with POST and PUT 将 Elastic Beanstalk 健康检查程序的协议更改为 HTTPS 而不是普通的 HTTP(应用程序负载均衡器) - Change protocol of Elastic Beanstalk health checker to HTTPS instead of plain HTTP (Application load balancer) AWS 应用程序负载均衡器抛出 502 - AWS Application load balancer throwing 502
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM