重新路由所有的HTTP流量到https与AWS ELB [英] Rerouting all http traffic to https with AWS ELB

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

问题描述

所以,我看过了其他类似的问题,他们提供解决方案,但他们都不工作,出于某种原因。因此,对于初学者来说,我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端口。

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]

但它似乎永远不会工作。是否有其他线路我失踪?有没有一种方法来检查它打的情况?我都试过的!HTTPS HTTP 的作为条件,但是都没有成功。

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.

编辑:稍微改变了我重写规则到现在它是什么,它​​仍然没有工作。我增加了一个额外的条件重写WWW和工作。 HTTP:X - 转发,原要么是不存在或不被负载平衡器设置

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

推荐答案

这只是你的重写规则这是无效的。请参阅这个帖子它如何应该看看。

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

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

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