Nginx ssh for each subdomain docker-container

I have a few NGINX sites like this:

server {

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

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # 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 = {
        return 301 https://$host$request_uri;
    } # managed by Certbot

listen        80;
    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