OpenBSD:如何使用 `relayd` 和 `httpd` 重定向子域请求

Jan*_*Jan 4 httpd reverse-proxy openbsd httpd.conf virtualhost

情况

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

vm-server-结构

所以我的 OpenBSD 服务器192.168.1.250将所有 http 请求重定向到host-vm192.168.30.2

host-vm本身nginx用于重定向子域请求,如下所示:

## 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;
    }
}
Run Code Online (Sandbox Code Playgroud)
  • 所以如果用户向foo.hermes-technology.de这个请求发送一个 http- request 将被重定向到host-vm.
  • 此后,host-vm根据子域名称将请求重定向到foo-vm.

我只想依赖 OpenBSD 的基本软件包,所以我的问题是:

如何将主机上的子域请求重定向到其他本地 ip 地址,仅使用httpd和实现与上述相同的结果relayd

更多信息

如果您需要或想要有关此设置的更多信息来回答我的问题,我在此处了整个配置: blog.hermes-technology.de

Pie*_*RET 8

关于中继,我想类似的东西会实现你想要的:

这定义了您可以在其中找到 foo“服务”的 ip,它基本上是一个主机列表(pf 样式)

table <fooservice> { 192.168.30.3 }
table <barservice> { 192.168.30.4 }
Run Code Online (Sandbox Code Playgroud)

在这里,您为要在中继部分应用的规则定义模板,您将请求与标题主机 foo.hermes-technology.de 匹配,在这种情况下,您转发到中继手册中表 fooservice 中的主机,他们说转发部分需要在中继部分匹配转发指令

http protocol "httpproxy" {

    pass request quick header "Host" value "foo.hermes-technology.de" \
        forward to <fooservice>

    pass request quick header "Host" value "bar.hermes-technology.de" \
        forward to <barservice>
    block
}
Run Code Online (Sandbox Code Playgroud)

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

relay "proxy" {
    listen on 192.168.30.2 port 80
    protocol "httpproxy"

    forward to <fooservice> port 80
    forward to <barservice> port 80
}
Run Code Online (Sandbox Code Playgroud)