log_format stream_log '$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received '
                      '$session_time "$ssl_preread_server_name" "$upstream_addr" '
                      '$upstream_bytes_sent $upstream_bytes_received';

access_log /var/log/nginx/stream/access.log stream_log;
error_log /var/log/nginx/stream/error.log;

map $ssl_preread_server_name $sni_name {
    www.vk.com      xray;
    vk.com          xray;
    www.eh.vk.com   xray;
    eh.vk.com       xray;
    tshk.duckdns.org    openconnect;
    moamo.duckdns.org   telemt;
    duckdns.org           www;
    ~^[^.]+\.duckdns\.org$  www;
    default              vk;
}

upstream xray {
    server 11.101.0.254:6443;
}

upstream www {
    server 127.0.0.1:7443;
}

upstream vk {
    server 87.240.137.164:443;
}

upstream openconnect {
    server 127.0.0.1:5443;
}

upstream telemt {
    server 11.101.0.254:9443;
}

server {
    listen          443;
    proxy_pass      $sni_name;
    ssl_preread     on;
    proxy_connect_timeout 5s;
    proxy_timeout   24h;
}
