user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /run/nginx.pid; events { worker_connections 1024; } stream { log_format proxy '$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time "$ssl_preread_server_name"'; access_log /var/log/nginx/stream-access.log proxy; upstream haproxy_http { server 127.0.0.1:10080; } upstream haproxy_backend_pp { server 127.0.0.1:19443; } upstream haproxy_backend_real { server 127.0.0.1:10443; } upstream stunnel_tun0_pp { server 127.0.0.1:28443; } upstream stunnel_tap0_pp { server 127.0.0.1:28444; } upstream stunnel_tun0_backend { server 127.0.0.1:8443; } upstream stunnel_tap0_backend { server 127.0.0.1:8444; } map $ssl_preread_server_name $backend { liqueur.oyacoi.ru stunnel_tun0_pp; absinthe.oyacoi.ru stunnel_tap0_pp; default haproxy_backend_pp; } server { listen {{ ip }}:80; proxy_pass haproxy_http; proxy_protocol on; } server { listen {{ ip }}:443; proxy_pass $backend; ssl_preread on; proxy_protocol on; } server { listen 127.0.0.1:19443 proxy_protocol; set_real_ip_from 127.0.0.1; proxy_pass haproxy_backend_real; proxy_protocol on; } server { listen 127.0.0.1:28443 proxy_protocol; set_real_ip_from 127.0.0.1; proxy_pass stunnel_tun0_backend; } server { listen 127.0.0.1:28444 proxy_protocol; set_real_ip_from 127.0.0.1; proxy_pass stunnel_tap0_backend; } }