Lighttpd 根据传入请求设置 X-Forwarded-Host

Lighttpd set X-Forwarded-Host based on incoming request

我目前正在使用 Lighttpd 作为代理来为不支持 HTTPS 的应用程序添加 HTTPS 加密。

为此,我使用以下配置:

# Listen to port 443
$SERVER["socket"] == ":443" {
  ssl.engine = "enable"
  include "ssl-params.conf"

  proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => 80 ) ) )
  setenv.add-request-header  = (
     "X-Forwarded-Proto" => "https",
     "X-Forwarded-Host" => "hardcoded.domain.com",
     "X-Forwarded-Port" => "443"
  )
  # Set Error/Log
  server.errorlog = "/var/log/lighttpd/error.log"
}

除一件事外,此配置有效。我必须硬编码 X-Forwarded-Host 的值。 直到最近这才成为问题,但现在我有多个域指向同一个代理并且需要转发正确的域名。

是否有任何方法可以从传入的 HTTPS 连接中提取主机以将正确的值提供给 X-Forwarded-Host

lighttpd 将 X-Host 请求 header 中的主机提供给后端,而不是使用 X-Forwarded-Host.

仅供参考:根据 https://redmine.lighttpd.net/issues/418, lighttpd is planning (in the future) to implement Forwarded HTTP Extension (https://www.rfc-editor.org/rfc/rfc7239)

顺便说一句,lighttpd 也已经在代理请求中添加了 X-Forwarded-Proto。