lighttpd配置从一个域代理/重写到另一个域

201*_*450 6 mod-rewrite lighttpd mod-proxy

我需要在lighttpd上设置代理/重写!

我有server1,它通过http 2不同的web应用程序路径提供服务:

* http://server1/path1
* http://server1/path2
Run Code Online (Sandbox Code Playgroud)

另外,我在server1前面有lighttpd服务器

我想在lighttpd上设置重写和/或代理,以便2条路径中的每条路径都可以作为不同域上的根路径:

* requests to http://server2.com/* are proxied/rewrited to http://server1/path1/*
* requests to http://server3.com/* are proxied/rewrited to http://server1/path2/*
Run Code Online (Sandbox Code Playgroud)

重要:

  • server2.com和server3.com 只能通过http访问server1
  • 重定向不是选项,server2.com和server3.com的用户不应该知道实际的Web应用程序是从server1的不同路径提供的.

可能吗?

Aiz*_*una 5

几年来,lighttpd开发人员已知道您的需求。

可以通过解决方法或新功能(取决于版本)来解决。

Lighttpd 1.4

在bugtracker中解释了一种解决方法:bug#164

$HTTP["url"] =~ "(^/path1/)" {   
  proxy.server  = ( "" => ("" => ( "host" => "127.0.0.1", "port" => 81 ))) 
}

$SERVER["socket"] == ":81" {   
  url.rewrite-once = ( "^/path1/(.*)$" => "/$1" )   
  proxy.server  = ( "" => ( "" => ( "host" => "server2.com", "port" => 80 ))) 
}
Run Code Online (Sandbox Code Playgroud)

Lighttpd 1.5

他们使用以下命令添加了此功能(官方文档):

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

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

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