Reverse-Proxy

使用 lighttpd 的跨平台反向代理

  • November 14, 2020

我有一個www.somewebsite.com託管在 lighttpd 1.4伺服器上的網站域,該伺服器配置在具有本地 IPserver.port = 8080的設備**(A)192.168.1.26上,我想使用反向代理來訪問在不同設備(B)**上執行192.168.1.30:80/myapp的另一台伺服器為了被訪問為

somewebsite.com/myapp

在設備**(A)**伺服器配置中,我已啟用mod_proxy 並嘗試添加

$HTTP["url"] =~ "^.*myapp" {
   proxy.server  = ( "" => 
       (( "(www.)?somewebsite.com" => "192.168.1.30", "port" => 80 ))
   )
}

但是當我嘗試訪問時出現內部伺服器錯誤頁面somewebsite.com/myapp

我也試過

$HTTP["url"] =~ "(^/myapp/)" {   
 proxy.server  = ( "" => ("" => ( "(www.)?somewebsite.com" => "127.0.0.1", "port" => 8080 ))) 
}

$SERVER["socket"] == ":81" {   
 url.rewrite-once = ( "^/myapp/(.*)$" => "/$1" )   
 proxy.server  = ( "" => ( "" => ( "(www.)?somewebsite.com" => "192.168.1.30", "port" => 80 ))) 
}

但結果更糟,伺服器完全崩潰

proxy.server不要將主機作為參數,並且“主機”是關鍵字,而不是將主機放在這裡的地方。

試試這個:

$HTTP["host"] =~ "(www.)?somewebsite.com" {
$HTTP["url"] =~ "^/myapp/" {
 url.rewrite-once = ("^/myapp/(.*)" => "/newapp/$1") # If you need to rewrite context.
 proxy.server  =  ( "" => ( "" => ("host" => "192.168.1.30", "port" => 80 )))
 }
}
$HTTP["host"] =~ "(www.)?somewebsite.com" {
 $HTTP["url"] =~ "^/myapp/" {
   url.rewrite-once = ("^/myapp/(.*)" => "/newapp/$1")
 }
 $HTTP["url"] =~ "^/newapp/" {
   proxy.server  =  ( "" => ( "" => ("host" => "192.168.1.30", "port" => 80 )))
 }
}

或者,您可以proxy.header"map-urlpath"lighttpd 1.4.46 及更高版本一起使用。見https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModProxy

引用自:https://serverfault.com/questions/1040764