使用 lighttpd 进行跨平台反向代理

使用 lighttpd 进行跨平台反向代理

www.somewebsite.com我有一个在 lighttpd 上托管的网站域名1.4配置了该服务器server.port = 8080的设备上(A)使用本地 IP 192.168.1.26,我想使用反向代理来访问在不同设备上运行的另一台服务器(二)以便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 ))) 
}

但结果更糟,服务器彻底崩溃

答案1

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

答案2

$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.headerlighttpd "map-urlpath"1.4.46 及更高版本。请参阅https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModProxy

相关内容