我需要在lighttpd上设置代理/重写!
我有 server1,它通过 http 2 不同的 Web 应用程序路径提供服务:
* http://server1/path1
* http://server1/path2
另外,我在 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/*
重要的:
是否可以?
最佳答案
多年来,lighttpd 开发人员都知道您的需求。
根据版本的不同,它会通过变通方法或新功能来回答。
Lighttpd 1.4
错误跟踪器中解释了一种解决方法: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 ))) }
Lighttpd 1.5
他们使用此命令( official documentation )添加了此功能:
proxy-core.rewrite-request : rewrite request headers or request uri.
$HTTP["url"] =~ "^/path1" { proxy-co... proxy-core.rewrite-request = ( "_uri" => ( "^/path1/?(.*)" => "/$1" ), "Host" => ( ".*" => "server2.com" ), ) }
关于mod-rewrite - 从一个域代理/重写到另一个域的 lighttpd 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14536554/