Virtual hosting with s6-networking

From: Songbo Wang <songbo_at_wsb.onl>
Date: Wed, 21 Sep 2022 01:27:10 +0200

Hi,

I am working on setting up the following "virtual hosting" with the
s6-networking tools:

- There are two domains, a.example.net and b.example.net, resolving to
the same machine
- For each HTTP(S) request to host a.example.net, port 80 (443), a
superserver will fork and exec httpd-a, with stdin/out reading/writing
to the network socket
- Similarly, for each HTTP(S) request to host b.example.net, port 80
(443), a superserver will fork and exec httpd-b, with stdin/out
reading/writing to the network socket
- httpd-{a,b} may be completely different programs, so we cannot rely on
them to react differently to HTTP(S) requests with different hosts

I can think of adding an auxiliary program, between s6-tcpserver4d and
the httpd programs, to distinguish requests to different hosts (for
HTTPS, it may be able to be done by distinguishing the SNI in the Client
Hello message, but I am totally not familiar with that). But is there a
way to do it "natively", without introducing new programs?

I thought about "multiplexing" the TCP connection, i.e. having two
superservers listening to the same network socket. This can be done with
s6-tcpserver4-socketbinder and fd holding mechanisms. And I've tried:

1. Launch a fdholder-daemon, with the right rules
2. Create a TCP socket, bind it to 127.0.0.1:8080, and store the fd in
the daemon
3. Retrieve the fd and exec s6-tcpserver4d
4. Do step 3 again

Then I test the setup by "nc 127.0.0.1 8080" and one of the two
s6-tcpserver4ds will complain it is not able to accept(). Is this kind
of setup even possible?

Thanks,
-- 
Songbo Wang (汪嵩博)
Received on Wed Sep 21 2022 - 01:27:10 CEST

This archive was generated by hypermail 2.4.0 : Wed Sep 21 2022 - 01:27:44 CEST