A new way to mix traffic of both HTTPS and SS proxy

The ngx_stream_ssl_preread module added in Nginx 1.11.5.

we can use 443 port serve HTTPS and SS proxy at the same time.

The configuration file of Nginx is as follows:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

stream {
	log_format stream_routing '$remote_addr [$time_local] '
                            'with SNI name "$ssl_preread_server_name" '
                            'proxying to "$name" '
                            '$protocol $status $bytes_sent $bytes_received '
                            '$session_time';

    map $ssl_preread_server_name $name {
        example.com web_backend;
        default ss_backend;
    }

    upstream web_backend {
        server 127.0.0.1:444;
    }

    upstream ss_backend {
        server 127.0.0.1:2333;
    }

    server {
        listen 0.0.0.0:443;
        proxy_pass $name;
        ssl_preread on;
		    access_log /var/log/nginx/stream_443.log stream_routing;
    }
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    client_max_body_size 100m;
    client_body_timeout 120s;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    upstream blog {
    	server 127.0.0.1:2368;
    }

    server {
        listen       80;
        server_name  example.com www.example.com;
    	  return 301 https://$server_name$request_uri;


        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {
        listen       444 ssl http2 default_server;
        server_name  example.com;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        location / {
            proxy_pass   http://blog;
            proxy_redirect off;
            proxy_set_header   Host $host;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

    }
}

Notes:

Replace the example.com of the above configuration file with your domain name.