大网数据广告活动
服务器运维问答

OpenBSD: How to use `relayd` and `httpd` for redirecting subdomain requests

· 52CE 我爱测

Situation I created the following setup on OpenBSD : So I have my OpenBSD server on 192.168.1.250 redirecting all http-requests to the host-vm on 192.168.30.2 . The host-vm itself operates nginx for redirecting subdomain-requests…

问题原文

原帖链接 · Jan · CC BY-SA 3.0

Situation

I created the following setup on OpenBSD:

So I have my OpenBSD server on 192.168.1.250 redirecting all http-requests to the host-vm on 192.168.30.2.

The host-vm itself operates nginx for redirecting subdomain-requests like so:

## 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;
    }
}
  • So if users send a http-request to foo.hermes-technology.de this request will be redirected to the host-vm.
  • Thereafter the host-vm redirects the request based on the name of the subdomain to the local ip of the foo-vm.

Question

I would like to be dependent only on base packages of OpenBSD, so my question is:

How is it possible to redirect subdomain requests on the host machine to other local ip-addresses, achieving the same result as above only using httpd and relayd?

More Information

If you need or want more information on this setup for answering my question I have a writeup of the whole configuration here: blog.hermes-technology.de.

已采纳解答

原帖链接 · Pierre-Alain TORET · CC BY-SA 3.0

concerning relayd I guess something like would achieve what you want :

This defines the ip where you can find the foo "service" it's a list of host basically (pf style)

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

Here you define a template for the rules to apply in a relay section you match the request with the header Host being foo.hermes-technology.de and in that case you forward to the host being in the table fooservice in the relayd manual they say that the forward section needs a matching forward instruction in the relay section

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
}

This defines the relay and uses both the tables and the protocol defined above.

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

    forward to <fooservice> port 80
    forward to <barservice> port 80
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。