Nginx ssh for each subdomain docker-container

I have a few NGINX sites like this:

server {
server_name   app1.domain.com;

location / {
    proxy_pass  http://localhost:8081;
}

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/app1.domain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/app1.domain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = app1.domain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

listen        80;
server_name   app1.domain.com;
    return 404; # managed by Certbot
}

One for app1, app2, app3 and so on..

The proxy_pass works fine for http traffic but I would also like to ssh separately into each container by using its subdomain, like:

ssh [email protected]

I tried to run the containers like:

docker run -dit --name flask_ssh -p 2002:22 -p 8081:80 flask_ssh_ready

Of course I can SSH into them by using their local IP like:

ssh [email protected]

but I still haven’t figured out how to connect the individual ssh port to its NGINX site/subdomain. A solution without having to specify a ssh port for each container would be better I guess.

Is there any system in place that provides such features in newer versions of NGINX?

Source: Docker Questions