ELB上的SSL,但使用Apache进行设置

KVI*_*ISH 2 apache django ssl amazon-web-services

现在我有一个启用SSL的网站.SSL处于ELB级别,因此apache http服务器永远不会看到它.我正在努力使Apache能够强制所有请求,https因此没有http请求.我正在阅读关于SO的其他几篇文章,包括:

Django和SSL问题

https://serverfault.com/questions/410542/disable-https-for-certain-path-in-nginx-results-in-instance-behind-elb-going-int

http://www.acmedata.in/2012/08/31/how-to-host-a-django-app-behind-elb-with-ssl/

我可以为此使用ELB配置吗?或者我是否必须从ELB中删除私钥等,并将其全部放在Web服务器级别?我无法找到有关此问题的任何进一步信息......

Dav*_*que 5

您可以通过向Apache配置添加这样的重写规则来强制https:

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

这里的关键是X-Forwarded-Proto标题.ELB处理https并将请求作为http转发给Apache,并且它还在此过程中添加了此标头.重写规则检查此标头仅重定向不源自ELB的http请求.