OpenBSD: How to use `relayd` and `httpd` for redirecting subdomain requests
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 thehost-vm
. - Thereafter the
host-vm
redirects the request based on the name of the subdomain to the local ip of thefoo-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.
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
}