AWS ALB重定向到https

编程入门 行业动态 更新时间:2024-10-27 00:22:37
本文介绍了AWS ALB重定向到https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的Apache服务器在ALB / ELB之后。我要在负载均衡器处终止SSL。负载均衡器同时监听80和443。我想将所有http请求重定向到https。

My Apache servers are behind an ALB/ELB. I'm terminating SSL at the load balancer. The load balancer listens on both 80 and 443. I want to redirect all http requests to https.

我在虚拟主机配置中有以下重写规则:

I have this rewrite rule in place in the vhost config:

RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} =http RewriteRule .* %{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

这可行,但是问题是我在htaccess文件中也有重定向。当通过htaccess文件发生重定向时,它将首先重定向到http,然后vhost配置重定向将其选中并重定向到https。我想消除多余的http重定向。

This works, but the issue is that I also have redirects in an htaccess file. When a redirect happens through the htaccess file, it redirects to http first and then the vhost config redirect picks it up and redirects to https. I want to eliminate the extra http redirect.

http:/ /mysite.example/sub 301 https:// mysite。 example/sub 301 mysite.example / newsub -此重定向为htaccess 301 https://mysite.example / newsub 200

mysite.example/sub 301 mysite.example/sub 301 mysite.example/newsub - this redirect is htaccess 301 mysite.example/newsub 200

我想轻松解决htaccess首先重定向到http的问题。我可以通过添加 https://% {HTTP:Host}重写规则来解决此问题。这是执行此操作的最佳方法吗?

I'd like to gracefully get around having the htaccess redirect to http first. I can get around this by adding %{HTTP:Host} to rewrite rules. Is this the best way to do this:

RewriteRule ^sub$ %{HTTP:Host}/newsub [R=301,L]

推荐答案

Application Load Balancer现在支持两项新操作:重定向和固定响应。您可以将这些操作配置为基于内容的路由规则的一部分,使您可以将此功能卸载到负载均衡器。这简化了部署,同时受益于Elastic Load Balancing的规模,可用性和可靠性。

Application Load Balancer now supports two new actions: redirect and fixed-response. You can configure these actions as part of the content-based routing rules, enabling you to offload this functionality to the load balancer. This simplifies deployments while benefiting from the scale, the availability, and the reliability of Elastic Load Balancing.

这就是我所做的,以使其在AWS上工作:

Here's what I did to make it work on AWS:

ALB重定向的示例配置-HTTP-> HTTPS

aws.amazon/about-aws/whats-new/2018/07 / elastic-load-balancing-announces-supports-redirects-and-fixed-respons-for-application-load-balancer /

更多推荐

AWS ALB重定向到https

本文发布于:2023-11-01 19:47:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550241.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   AWS   ALB   https

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!