19

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 上的 Web 服务器,DeviceC 应该以 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)

4

2 回答 2

17

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 ))) 
}

轻量级 1.5

他们用这个命令(官方文档)添加了这个特性:

proxy-core.rewrite-request:重写请求标头或请求 uri。

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

  proxy-core.rewrite-request = (
    "_uri" => ( "^/DeviceB/?(.*)" => "/$1" ),
    "Host" => ( ".*" => "192.168.1.20" ),
  )
}
于 2013-10-19T13:46:07.650 回答
6

所需包

server.modules  =  (
...
   "mod_proxy",
...
)

您的前端代理设置:对于 lighttpd.conf @192.168.1.10

$HTTP["url"] =~ "^.*DeviceB" {
    proxy.server  = ( "" => 
        (( "host" => "192.168.1.20", "port" => 80 ))
    )
}

$HTTP["url"] =~ "^.*DeviceC" {
    proxy.server  = ( "" => 
        (( "host" => "192.168.1.30", "port" => 80 ))
    )
}

lighttpd mod_proxy的完整文档可以参考http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModProxy

于 2012-07-27T10:42:25.537 回答