Score:0

Proxy/Route requests to subdomains to different local/wireguard IP addresses?

cn flag

We have a virtual machine with a public IPv4 address, to which our example.com and *.example.com domain points.

We have several distributed low-tech computers establishing a wireguard connection/tunnel with the publicly reachable virtual machine.

We want the virtual machine to serve a website on ports 80/443, accept ssh connections via port 22, and more.

We want the low-tech computers to be publicly reachable, via respective subdomains like low-tech-01.example.com, low-tech-02.example.com, et cetera, and proxying/routing requests to respective local/wireguard IP addresses. This should work for websites via ports 80/443, ssh connections via port 22, and more.

Edit: Idealy, the SSL certificates should be served from the low-tech computers, and the SSL connection should not be terminated on the virtual machine.

Edit: Ideally, the ssh private keys for establishing the connection to the low-tech computers should not exist on the virtual machine, but only on the client.

Edit: For ssh, we could open and route one unique port for each of the low-tech computers from public_IPv4:22xxx to local/wireguard_IP:22

Unfortunately, after spending two days with nginx configuration trial and error, we figured that this task probably cannot be solved by nginx alone.

Note: ssh does not send SNI; nginx cannot listen on the same ports for http as well as stream connections; and maybe more problems.

But also, we’re completely out of ideas and overwhelmed by which approach could indeed properly solve this task.

(www\.)?example.com –> public IPv4 –> website, ssh, etc.

low-tech-01.example.com –> public IPv4 –> ??? ~> 10.0.0.101 –> website, ssh, etc.

low-tech-02.example.com –> public IPv4 –> ??? ~> 10.0.0.102 –> website, ssh, etc.

Thank you for your advice and time.

Edit: The following nginx stream config is close to what we’re trying to achieve. The (maybe) only downside is that we’d have to manually define a port for each low-tech computer instead of having this handled dynamically like for SSL connections.

stream {
  map $ssl_preread_server_name $name {
    example.com example.com;
    www.example.com example.com;
    low-tech-01.example.com low-tech-01.example.com;
    low-tech-02.example.com low-tech-02.example.com;
  }

  upstream example.com {
    server 127.0.0.1:8443;
  }

  upstream low-tech-01.example.com {
    server 10.0.0.101:443;
  }

  upstream low-tech-02.example.com {
    server 10.0.0.102:443;
  }

  server {
    listen 443;
    proxy_pass $name;
    ssl_preread on;
  }

  server {
    listen 22101;
    proxy_pass 10.0.0.101:22;
  }

  server {
    listen 22102;
    proxy_pass 10.0.0.102:22;
  }

  …
}
Ivan Shatsky avatar
gr flag
Maybe you can use `s_client` command from the client machines when connecting via SSH protocol? Check [this](https://serverfault.com/a/1023845/498657) answer.
A.B avatar
cl flag
A.B
Have a look at this Q/A to understand the limitation: https://serverfault.com/questions/878080/how-do-i-make-protocol-foo-hostname-aware
Score:0
us flag

You need to get multiple IP addresses on the server, one for each of the subdomains you want to use.

Then you need to assign a public IP address to each VM. After that you can bind the subdomain to the IP address. In the VM, one can do port forwarding to whichever final destination one wants.

fooness avatar
cn flag
Thank you for you answer. Unfortunately this does not solve the problem. If there were public IPv4 addresses available, then we wouldn’t need the VM to proxy/route the requests.
us flag
That is the only option for SSH if you want to map domains to different instances. Another option is separate TCP ports for each domain, and then do port forwarding.
fooness avatar
cn flag
Separate TCP ports for each domain is what we ended up using for now, yes. We wish, though, that this could happen somehow dynamically instead of manually creating an entry for each port in e.g. our nginx `stream` block.
us flag
Whatever the mechanism is, you need to manage its configuration somehow. A configuration management system should help with it.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.