gpt4 book ai didi

lighttpd 作为反向代理

转载 作者:行者123 更新时间:2023-12-02 11:08:25 27 4
gpt4 key购买 nike

DeviceA 充当反向代理,并应按如下方式转发请求:

192.168.1.10/DeviceB ==> 192.168.1.20/index.html

192.168.1.10/DeviceC ==> 192.168.1.30/index.html

两个索引文件都位于/var/www 下,并且是静态的“Hello world!”页。问题是我无法通过 DeviceA 访问这些文件,但如果我调用也在 DeviceC 上运行的测试服务(监听端口 12345),则一切正常。

如果请求在端口 80 上传入,DeviceB、DeviceC 上的 Web 服务器应该以 index.html 进行响应,我这样说是不是错了???

lighttpd.conf DeviceA @192.168.1.10 server.modules = (“mod_proxy”)

proxy.server = ( 
"/DeviceB" => ( "" => ( "host" => "192.168.1.20", "port" => 80 )),
"/DeviceC" => ( "" => ( "host" => "192.168.1.30", "port" => 80 )),
"/TestService" => ( "" => ( "host" => "192.168.1.30", "port" => 12345 ))
)

lighttpd.conf DeviceB @192.168.1.20

server.document-root = "/var/www"
server.port = 80
index-file.names = ( "index.html" )

lighttpd.conf DeviceC @192.168.1.30

server.document-root = "/var/www"
server.port = 80
index-file.names = ( "index.html" )
<小时/>

更新

我需要 $HTTP["host"] == ... proxy.server() 来重写/重定向 URL 吗?或者,如何定义什么应该被代理(ed)

最佳答案

lighttpd 开发人员多年来都知道您的需求。

根据版本,可以通过解决方法或新功能来解决这个问题。

Lighttpd 1.4

bugtracker 中解释了解决方法:bug #164

$HTTP["url"] =~ "(^/DeviceB/)" {   
proxy.server = ( "" => ("" => ( "host" => "127.0.0.1", "port" => 81 )))
}

$SERVER["socket"] == ":81" {
url.rewrite-once = ( "^/DeviceB/(.*)$" => "/$1" )
proxy.server = ( "" => ( "" => ( "host" => "192.168.1.20", "port" => 80 )))
}

Lighttpd 1.5

他们通过以下命令添加了此功能 ( official documentation ):

proxy-core.rewrite-request : rewrite request headers or request uri.

$HTTP["url"] =~ "^/DeviceB" {
proxy-co...

proxy-core.rewrite-request = (
"_uri" => ( "^/DeviceB/?(.*)" => "/$1" ),
"Host" => ( ".*" => "192.168.1.20" ),
)
}

关于lighttpd 作为反向代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4859956/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com