lighttpd 作为反向代理
DeviceA 充当反向代理,并应按如下方式转发请求:
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),则一切正常。
如果请求在端口 80 上传入,DeviceB、DeviceC 上的 Web 服务器应该以 index.html 进行响应,我这样说是不是错了?
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" )
更新
我需要吗$HTTP["host"] == ... 围绕 proxy.server() 重写/重定向 URL?或者,如何定义什么应该被代理(编辑)
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
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.
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" )
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" )
Update
Do I need $HTTP["host"] == ... around proxy.server() to rewrite/redirect URLs? Or, how to define what shall be proxy(ed)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
lighttpd 开发人员多年来都知道您的需求。
根据版本的不同,可以通过解决方法或新功能来解决这个问题。
Lighttpd 1.4
bugtracker 中解释了解决方法:bug #164
Lighttpd 1.5
他们使用此命令添加了此功能(官方文档):
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
A workaround is explained in the bugtracker : bug #164
Lighttpd 1.5
They added this feature with this command (official documentation) :
所需包
您的前端代理设置:针对 lighttpd.conf @192.168.1.10
lighttpd mod_proxy 的完整文档,您可以参考 http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModProxy
Required package
Your frontend proxy setting : for lighttpd.conf @192.168.1.10
For the full documentation of lighttpd mod_proxy, you can refer to http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModProxy
使用
proxy.header
的Lighttpd 1.4 的另一个非解决方案(从 1.4.46 版本开始提供,使用版本 1.4.53 进行测试):
不幸的是,
map- urlpath
只能替换 URL 的前缀,但这涵盖了大多数情况,包括这种情况。有关详细信息,请参阅
mod_proxy
的文档。Another, non-workaround solution for Lighttpd 1.4
Using
proxy.header
(available since version 1.4.46, tested using version 1.4.53):Unfortunately,
map-urlpath
is only able to replace the prefix of the URL, but that covers most cases including this one.For details refer to the documentation of
mod_proxy
.