我的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
发布评论