在AWS负载均衡器上强制使用https和www [英] Force https and www on AWS load balancer

查看:85
本文介绍了在AWS负载均衡器上强制使用https和www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS负载均衡器,当前正在使用此.htaccess正则表达式将所有http重定向到https:

I'm using an AWS load balancer and currently redirecting all http to https with this .htaccess regex:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

这很好,因为我有必须在80上访问的运行状况检查。但是,当前在尝试访问https www时,我得到了DNS错误。

This works fine because I have health checks that must be accessed on 80. However, currently when trying to access https www I get a DNS error.

正则表达式看起来像什么,将所有内容路由到 https:// www 并通过了运行状况检查

What would regex look like that routes everything to https://www and passes a health check on http on my instances?

谢谢!

推荐答案

在负载平衡器背后的AWS,您必须以不同的方式处理事情。由于负载平衡器的SSL卸载功能,您将不会以常规方式检查https。您需要检查X-Forwarded-Proto

At AWS behind the load balancer, you have to handle things differently. You won't be checking for https in the normal way because of the SSL Offloading with your Load Balancer. You would need to check the X-Forwarded-Proto

应如下所示。

 RewriteEngine On
 RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
 RewriteCond %{HTTP_HOST} !^www\. [NC]
 RewriteCond %{SERVER_NAME} ^(www\.)?(.*)$ [NC]
 RewriteRule ^.*$ https://www.%2%{REQUEST_URI} [R=301,L]` 

这篇关于在AWS负载均衡器上强制使用https和www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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