使用 AWS ELB 将所有 http 流量重新路由到 https [英] Rerouting all http traffic to https with AWS ELB

查看:46
本文介绍了使用 AWS ELB 将所有 http 流量重新路由到 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我查看了其他类似的问题,他们提供了解决方案,但由于某种原因,它们似乎都不起作用.所以,对于初学者来说,我的 ELB 是这样设置的

So I've looked over the other similar questions and they offer solutions but none of them seem to work for some reason. So, for starters, my ELB is set up so that

HTTP (incoming) -> HTTP (instance)
HTTPS (incoming) -> HTTP (instance)

所以两个流量都应该在端口 80 上进入.这有效,就像我使用 http://mydomain.com 访问我的网站时一样,或者https://mydomain.com,即使我在端口 80 上只有一个 VirtualHost,它也能显示.

So both traffic should come in on port 80. And this works, as when I access my site using http://mydomain.com or https://mydomain.com, it is able to display even though I only have a VirtualHost for on port 80.

问题在于尝试将所有 http 流量重写为 https.我过去常常根据端口进行操作(检查是否为 !443 并重写为 https),但现在一切都将变为 80,这将不起作用.所以我正在运行 Apache 服务器并使用此重写规则

The issue is with attempting to rewrite all http traffic to https. I use to do it based on ports (check if !443 and rewrite to https) but that won't work now that everything is going into 80. So I'm running an Apache server and have this rewrite rule

RewriteEngine on
RewriteCond %{HTTP_HOST} www.(.+) [OR,NC]    # Added
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^/?(.*) https://mydomain.com%{REQUEST_URI} [L,R=301]

但它似乎永远不会奏效.我还缺少其他线路吗?有没有办法检查它是否达到该条件?我尝试了 !httpshttp 作为条件,但都没有奏效.

But it never seems to work. Are there other lines I'm missing? Is there a way to check that it's hitting that condition? I tried both !https and http as the condition and neither worked.

将我的 RewriteRule 稍微更改为现在的样子,但它仍然无法正常工作.我添加了一个额外的条件来重写 www 并且有效.HTTP:X-Forwarded-Proto 要么不存在,要么未被负载均衡器设置

edit: Slightly changed my RewriteRule to what it is now and it's still not working. I added an extra condition to rewrite www and that works. HTTP:X-Forwarded-Proto either isn't there or isn't set by the load balancer

这个错误真的很愚蠢.我只是 SSH 进入错误的实例.谢谢你忍受我的愚蠢

edit: The mistake was REALLY dumb. I was simply SSHing into the wrong instance. Thanks for putting up with my foolishness

推荐答案

只是您的 RewriteRule 无效.请参阅这篇文章,了解如何应该看看.

It's just your RewriteRule which is not valid. Please see this post on how it should look.

这篇关于使用 AWS ELB 将所有 http 流量重新路由到 https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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