It was necessary to implement a specialized case: there is a certain balancer, which must receive and redirect arbitrary HTTP and HTTPS requests, not having on hand any certificates or previously known addresses to which requests should be redirected. Technically, this is implemented using SNI (get server name -> redirect the tcp stream to it), but all the examples on the Internet are reduced to redirecting to a previously known address, and the configuration with predefined addresses has already begun to swell.
Is it possible to configure nginx in such a way that it extracts the FQDN from the SNI, resolves it (the final addresses are specified in the local DNS), and redirects the TCP stream to the received IP?
Actually it is required to make banal
server { listen 80; proxy_pass $host; } But given the fact that traffic is encrypted at 443, and the host can only be extracted from SNI.