3

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 specific 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

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. 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.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. – SpenserWilson1 Feb 9 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.