'ssh routing to subdomains

I have a server set up which I ssh into, and I'm running gitlab in a docker container on it and routing the http and https traffic to it through nginx using a subdomain. That works fine, but I want to do something similar with ssh so that I can use ssh+git. Currently ssh is exposed to the host on 10022, but I don't want to have to open a second ssh port, want I want to do is be able to do this:

# To ssh into the server
ssh example.com

# To use ssh+git on gitlab
git clone ssh://[email protected]/me/project.git

I'm guessing that what I want is some way to inspect the hostname used and forward to the appropriate internal port in a similar way that nginx does it for html trafficw, but I have no idea how to get started. Is this possible, and if so are there any guides that illustrate how to do it?



Solution 1:[1]

I am in the same situation with Gitea and this documentation describes in detail what to do:

Since SSH is running inside the container, SSH needs to be passed through from the host to the container if SSH support is desired. One option would be to run the container SSH on a non-standard port (or moving the host port to a non-standard port). Another option which might be more straightforward is for Gitea users to ssh to a Gitea user on the host which will then relay those connections to the docker.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1