Nginx can be configured to route to a backend, based on the server's domain name, which is included in the SSL/TLS handshake (Server Name Indication, SNI).
This works for http upstream servers, but also for other protocols, that can be secured with TLS.
This was tested with the nginx:1.15.9-alpine docker image.
Pass the TLS stream to an upstream server, based on the domain name from TLS SNI field. This does not terminate TLS.
The upstream server can serve HTTPS or other TLS secured TCP responses.
stream {
map $ssl_preread_server_name $targetBackend {
ab.mydomain.com upstream1.example.com:443;
xy.mydomain.com upstream2.example.com:443;
}
server {
listen 443;
proxy_connect_timeout 1s;
proxy_timeout 3s;
resolver 1.1.1.1;
proxy_pass $targetBackend;
ssl_preread on;
}
}Terminate TLS and forward the plain TCP to the upstream server.
stream {
map $ssl_server_name $targetBackend {
ab.mydomain.com upstream1.example.com:443;
xy.mydomain.com upstream2.example.com:443;
}
map $ssl_server_name $targetCert {
ab.mydomain.com /certs/server-cert1.pem;
xy.mydomain.com /certs/server-cert2.pem;
}
map $ssl_server_name $targetCertKey {
ab.mydomain.com /certs/server-key1.pem;
xy.mydomain.com /certs/server-key2.pem;
}
server {
listen 443 ssl;
ssl_protocols TLSv1.2;
ssl_certificate $targetCert;
ssl_certificate_key $targetCertKey;
proxy_connect_timeout 1s;
proxy_timeout 3s;
resolver 1.1.1.1;
proxy_pass $targetBackend;
}
}
Use at least nginx 1.15.9 to use variables in ssl_certificate and ssl_certificate_key.
Hi @rayray221,
sorry for the late answer. Did you already find a solution?
Do I understand correctly? You have one nginx. And you want to configure at the same time:
non terminating, TLS pass throughforhello.example.comterminating TLS, forward TCPforworld.example.comI'm not a super nginx expert, but I think it will work, but not on the same port.
I think you need something like this:
As you see, I choose two different ports (443 and 8443)
But, I'm not sure, I did not test this