Multiplexing HTTPS Upstreams on Port 443 With Nginx Stream SNI
When a single host serves multiple independent TLS backends on standard port 443, terminating TLS at the outer edge is not always desirable. Some upstreams manage their own certificates or require end-to-end handshake integrity.
Using ngx_stream_ssl_preread_module
With Nginx's stream module and ssl_preread on;, Nginx inspects only the unencrypted Server Name Indication (SNI) inside the initial ClientHello packet without decrypting the session:
nginx.conf
stream {
map $ssl_preread_server_name $upstream {
app.example.com 127.0.0.1:9443;
default 127.0.0.1:8443;
}
server {
listen 443;
ssl_preread on;
proxy_pass $upstream;
}
}
Operational Takeaways
Always move your HTTP virtual hosts to a loopback port such as 127.0.0.1:8443 before restarting Nginx, and run nginx -t to catch port-binding collisions before applying changes.