Use header variable in NGINX to forward traffic
Solution 1:
Your intention seems to be to pass through TLS connection via nginx stream
module. If you want to target different destinations depending on the SNI field of TLS header, then you need to use the following configuration:
map $ssl_preread_server_name $destination {
host1.example.com backend1;
host2.example.com backend2;
default backend3;
}
stream {
upstream backend1 {
server 192.168.100.1:443;
}
upstream backend2 {
server 192.168.100.2:443;
}
upstream backend3 {
server 192.168.100.3:443;
}
server {
listen 127.0.0.1:443;
proxy_pass $destination;
}
}