AWS ALB重定向到https [英] AWS ALB redirect to https

查看:771
本文介绍了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 .* https://%{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.com/sub
301
https:// mysite。 example.com/sub
301
http://mysite.example.com / newsub -此重定向为htaccess
301
https://mysite.example .com / newsub
200

http://mysite.example.com/sub 301 https://mysite.example.com/sub 301 http://mysite.example.com/newsub - this redirect is htaccess 301 https://mysite.example.com/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 https://%{HTTP:Host} to rewrite rules. Is this the best way to do this:

RewriteRule ^sub$ https://%{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

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

这篇关于AWS ALB重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆