Lighttpd 反向代理 HTTPS 到 HTTP 上的另一台服务器

Lighttpd reverse proxy HTTPS to another server on HTTP

我在 HTTPS 上有一个 Lighttpd 服务器 运行,我希望服务器上有一个子目录作为在 HTTP 上运行的单独服务器的反向代理。我已经尝试按照有关代理和 url 重写的指南进行操作,但是与 SSL 设置方式有关的一些事情会产生干扰。

$SERVER["socket"] == ":81" {
    url.rewrite-once = ( "^/directory/(.*)$" => "/index.html" )
    proxy.server  = ( "" => ( "" => ( "host" => "192.0.0.1", "port" => 123 )))
}

$HTTP["scheme"] == "http" {
     $HTTP["host"] =~ ".*" {
        url.redirect = (".*" => "https://%0[=10=]")
     }
}

$SERVER["socket"] == ":443" {
        ssl.engine = "enable"
        ssl.ca-file = "/etc/lighttpd/fullchain.pem"
        ssl.pemfile = "/etc/lighttpd/server.pem"
        $HTTP["url"] =~ "^/directory/" {
               proxy.server = ( "" => ( "" => ( "host" => "127.0.0.1", "port" => 81)))
        }
}

我的意图是转到 /directory/ 会将您重定向到 192.0.0.1:123/index.html。我按照 this guide 提到的第一个重定向到端口 81,然后将端口 81 重定向到第二个服务器。

这似乎不起作用,只是陷入重定向循环,并且总是 returns 301 到 https 站点。

如果我不执行 :81 重定向,我可以获得底部 proxy.server 以重定向到正确的位置,但它会保留 /directory/ 结尾,这不会到达我需要的位置它。

谢谢。

从 lighttpd 1.4.46 开始,mod_proxy 可以重写 url-prefixes。

$HTTP["scheme"] == "http" {
     $HTTP["host"] =~ ".*" {
        url.redirect = (".*" => "https://%0[=10=]")
     }
}

$SERVER["socket"] == ":443" {
        ssl.engine = "enable"
        ssl.ca-file = "/etc/lighttpd/fullchain.pem"
        ssl.pemfile = "/etc/lighttpd/server.pem"
        $HTTP["url"] =~ "^/directory/" {
               url.rewrite-once = ( "^/directory/(.*)$" => "/directory/index.html" )
               proxy.header = ( "map-urlpath" => ("/directory/" => "/") )
               proxy.server = ( "" => ( "" => ( "host" => "192.0.0.1", "port" => 123)))
        }
}