【问题标题】:Lighttpd reverse proxy HTTPS to another server on HTTPLighttpd 反向代理 HTTPS 到 HTTP 上的另一台服务器
【发布时间】:2019-01-15 17:36:27
【问题描述】:

我有一台在 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$0")
     }
}

$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 重定向到第二个服务器。

这似乎不起作用,只是卡在重定向循环中,并且总是向 https 站点返回 301。

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

谢谢。

【问题讨论】:

    标签: https reverse-proxy lighttpd mod-proxy


    【解决方案1】:

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

    $HTTP["scheme"] == "http" {
         $HTTP["host"] =~ ".*" {
            url.redirect = (".*" => "https://%0$0")
         }
    }
    
    $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)))
            }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-20
      • 2013-12-20
      • 2013-04-02
      • 2010-11-27
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 2017-05-21
      • 2020-06-21
      相关资源
      最近更新 更多