在lighttpd配置中访问X-Forwarded-Proto

时间:2015-02-09 16:44:38

标签: ssl amazon-web-services https load-balancing lighttpd

我在AWS负载均衡器后面有一个lighttpd服务器。 ELB为我处理所有SSL内容,并通过端口80上的HTTP将请求转发给lighttpd,并在此过程中设置X-Forwarded-Proto标头。

由于我只希望通过HTTPS和其他所有内容通过HTTP访问,我想在lighttpd配置文件中设置重定向,例如:

$HTTP["scheme"] == "https" {
    $HTTP["host"] !~ ".*ttc/(index.html)?$" {
        $HTTP["host"] =~ "(.*)" {
            url.redirect = ( "^(.*)$" => "http://%1$1")
        }
    }
}

当然,这不起作用,因为lighttpd只能看到HTTP请求......

我查看了mod_extforward,但这似乎只能提供对X-Forwarded-For标头的访问。

我会很感激有关如何解决这个问题的任何建议,而不必放弃lighttpd。

2 个答案:

答案 0 :(得分:0)

我找不到答案,所以我使用端口配置攻击如下:

HTTPS 443 (elb) => 80 (instance)
HTTP  80  (elb) => 81 (instance)

并在Lighttpd配置中:

$SERVER["socket"] == ":81" {
    # capture vhost name with regex conditiona -> %0 in redirect pattern
    # must be the most inner block to the redirect rule
    $HTTP["host"] =~ ".*" {
        url.redirect = (".*" => "https://%0$0")
    }
}

所以基本上当Lighttpd检测到连接到81时,它只是将其重定向到https。

答案 1 :(得分:0)

您使用的是什么版本的lighttpd?我正在查看1.4.36并看到mod_extforward.c确实处理了X-Forwarded-Proto。

如果使用lighttpd 1.4.36仍然无法解决这个问题,可能需要在lighttpd.conf中的某些其他模块之前加载mod_extforward吗?