2011-02-01 116 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"), 
) 
}