lighttpd作为反向代理

imp*_*mpf 15 reverse-proxy lighttpd mod-proxy

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),一切正常.

我错了说DeviceB上的Web服务器,如果端口80上有请求,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 ))
)
Run Code Online (Sandbox Code Playgroud)

lighttpd.conf DeviceB @ 192.168.1.20

server.document-root = "/var/www"
server.port = 80
index-file.names = ( "index.html" )
Run Code Online (Sandbox Code Playgroud)

lighttpd.conf DeviceC @ 192.168.1.30

server.document-root = "/var/www"
server.port = 80
index-file.names = ( "index.html" )
Run Code Online (Sandbox Code Playgroud)

更新

我需要$ HTTP ["host"] == ...围绕proxy.server()来重写/重定向网址吗?或者,如何定义代理内容(ed)

Aiz*_*una 14

几年来,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 ))) 
}
Run Code Online (Sandbox Code Playgroud)

Lighttpd 1.5

他们在此命令中添加了此功能(官方文档):

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

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

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


Pic*_*tor 6

必需的包

server.modules  =  (
...
   "mod_proxy",
...
)
Run Code Online (Sandbox Code Playgroud)

您的前端代理设置:对于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 ))
    )
}
Run Code Online (Sandbox Code Playgroud)

有关lighttpd mod_proxy的完整文档,请参阅http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModProxy