6

I have a server that is only accessible through a single port (I use a VPN with port forwarding). I have setup a reverse proxy using NGINX for some HTTPS servers that I'm hosting.

I'm wondering if I can do something similar where I can specify a location, and it redirects to a LAN IP with the ssh port 22.

location /ssh/ {
  proxy_pass      192.168.1.44:22;
}

I know proxy_pass only works for HTTP, but I'm wondering if there is something that would work for ssh.

1 Answer 1

5

This is a good question. Yes you can use nginx to redirect SSH traffic. In the following example, nginx will redirect traffic, according to protocol. This means that nginx is able to identify SSH traffic and redirect to SSH server, and also identify HTTPS traffic, and redirect to a web server.

In this example 10.10.10.4 is the SSH server, while 10.10.10.5 is the web server in the backend (behind nginx proxy)

stream {
    upstream ssh {
        server 10.10.10.4:22;
    }

    upstream web {
        server 10.10.10.5:443;
    }

    map $ssl_preread_protocol $upstream {
        default ssh;
        "TLSv1.2" web;
    }

    # SSH and SSL on the same port
    server {
        listen 443;

        proxy_pass $upstream;
        ssl_preread on;
    }
}
1
  • Thank you for this, but now I'm wondering if it's possible to set it up this way with also an RDP port. I am able to either ssh or RDP into my server when I specify the correct port number (22 or 3389), but I can't figure out a way to have both methods. Commented Feb 9, 2021 at 22:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .