小编pan*_*nt0的帖子

使用 AWS Elastic 负载均衡器强制使用 HTTPS

我需要将所有传入的 HTTP 流量重定向到我的弹性负载均衡器上的 HTTPS。

我厌倦了使用 Apache mod_rewrite:

 RewriteEngine On
 RewriteCond %{HTTP:X-Forwarded-Proto} !https
 RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
Run Code Online (Sandbox Code Playgroud)

利用负载均衡器添加的 X-Forwarded-Proto 标头,此规则应指示用户浏览器请求同一 URL 的 HTTPS 版本。

到目前为止它不起作用(没有重定向发生)。

我究竟做错了什么?

有一个更好的方法吗?

编辑:

这最终奏效了:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)

http https amazon-web-services apache-2.2 amazon-elb

7
推荐指数
1
解决办法
9771
查看次数