OpenBSD:如何使用relayd和httpd来redirect子域请求

情况

我在OpenBSD上创build了以下设置:

VM服务器结构

所以我有192.168.1.250上的OpenBSD服务器将所有的http请求redirect到192.168.1.250上的host-vm

host-vm自己使用nginx来redirect子域请求,如下所示:

 ## the virtual server for the foo-vm server { listen 80; server_name foo.hermes-technology.de; location / { proxy_pass http://192.168.30.3; } } ## the virtual server for the bar-vm server { listen 80; server_name bar.hermes-technology.de; location / { proxy_pass http://192.168.30.4; } } 
  • 所以如果用户发送一个http请求到foo.hermes-technology.de这个请求将被redirect到host-vm
  • 此后, host-vm将基于子域名称的请求redirect到foo-vm的本地ip。

我想只依赖于OpenBSD的基础包,所以我的问题是:

如何才能主机上的子域请求redirect到其他本地ip地址,只有使用httpdrelayd才能获得与上述相同的结果?

更多信息

如果您需要或想要了解更多有关此设置的信息以回答我的问题,请参阅blog.hermes-technology.de 。

关于relayd,我想这样的事情会达到你想要的:

这个ip定义了你在哪里可以findfoo“service”这个主机列表(pf style)

 table <fooservice> { 192.168.30.3 } table <barservice> { 192.168.30.4 } 

在这里你定义了一个模板,规则应用在一个中继部分,你匹配的请求与头部主机是foo.hermes-technology.de,在这种情况下,你转发到主机在relayd手册表fooservice他们说前面部分在中继部分需要一个匹配的正向指令

 http protocol "httpproxy" { match request quick header "Host" value "foo.hermes-technology.de" \ forward to <fooservice> match request quick header "Host" value "bar.hermes-technology.de" \ forward to <barservice> } 

这定义了中继,并使用上面定义的表和协议。

 relay "proxy" { listen on 192.168.30.2 port 80 protocol "httpproxy" forward to <fooservice> port 80 forward to <barservice> port 80 }