2011-02-01 112 views
12

DeviceA用作反向代理和应该转发请求如下:lighttpd的作为反向代理

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服务器,DeviceC应该用index.html响应,如果端口80上有请求?

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 [ “主机”] == ...周围proxy.server()重写/重定向的URL?或者说,如何界定什么事代理(ED)

+5

应该对serverfault,没有那么 – 2011-02-01 19:49:52

回答

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

10

您的需求由几年来的lighttpd开发人员所知。

根据版本的不同,它采用了解决方法或新功能。

Lighttpd的1.4

一种解决方法是在错误追踪解释: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)此功能:

代理core.rewrite请求:重写请求头或请求URI。

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

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