lighttpd作为反向代理 [英] lighttpd as reverse-proxy
问题描述
DeviceA充当反向代理,并应按以下方式转发请求:
DeviceA serves as a reverse-proxy and is supposed to forward requests as follows:
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上监听),一切正常.
Both index files are located under /var/www and are static "Hello world!" pages. The problem is that I can't access those files through DeviceA, but if I call a test service also running on DeviceC (listening on port 12345) everything works fine.
我是不是说DeviceB,DeviceC上的Web服务器应该在端口80上发出请求时用index.html进行响应?
Am I wrong saying that the web server on DeviceB, DeviceC should respond with index.html if a request comes in on port 80 ???
lighttpd.conf DeviceA @ 192.168.1.10 server.modules =("mod_proxy")
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" )
更新
在proxy.server()周围是否需要$ HTTP ["host"] == ...来重写/重定向URL?或者,如何定义应代理的内容
Do I need $HTTP["host"] == ... around proxy.server() to rewrite/redirect URLs? Or, how to define what shall be proxy(ed)
推荐答案
Lighttpd开发人员已经知道您的需求已有几年了.
Your need is known by lighttpd developers from several years.
可以通过变通方法或新功能来回答,具体取决于版本.
It is answered by a workaround or new feature depending on the version.
Lighttpd 1.4
错误跟踪程序中介绍了一种解决方法:错误#164
A workaround is explained in the bugtracker : 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
他们通过以下命令添加了此功能(官方文档):
They added this feature with this command (official documentation) :
proxy-core.rewrite-request :重写请求标头或请求uri.
proxy-core.rewrite-request : rewrite request headers or request uri.
$HTTP["url"] =~ "^/DeviceB" {
proxy-co...
proxy-core.rewrite-request = (
"_uri" => ( "^/DeviceB/?(.*)" => "/$1" ),
"Host" => ( ".*" => "192.168.1.20" ),
)
}
这篇关于lighttpd作为反向代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!