How to configure NGINX as a reverse proxy for different port numbers?

Ole
I have NGINX configured like this as a reverse proxy for http requests:

server {
    listen 80;
    server_name 203.0.113.2;

    proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP

    location / {
        proxy_pass http://203.0.113.1:3000;
    }
}

I also want to proxy ssh (Port 22) requests. Can I add another server block like this to the same configuration file:

server {
    listen 22;
    server_name 203.0.113.2;

    proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP

    location / {
        proxy_pass http://203.0.113.1:22;
    }
}

Such that the end result is this:

server {
    listen 80;
    server_name 203.0.113.2;

    proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP

    location / {
        proxy_pass http://203.0.113.1:3000;
    }
}
server {
    listen 22;
    server_name 203.0.113.2;

    proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP

    location / {
        proxy_pass http://203.0.113.1:22;
    }
}

TIA,
Ole

cnst

The ssh protocol is not based on HTTP, and, as such, cannot be proxied through the regular proxy_pass of ngx_http_proxy_module

However, recently, starting with nginx 1.9.0 (released as stable with 1.10.0 on 2016-04-26), nginx did gain support for doing TCP stream proxying, which means that if you have a recent-enough version of nginx, you can, in fact, proxy ssh connections with it (however, note that you wouldn't be able to add anything like the X-Real-IP to the proxied connection, as this is not based on HTTP).

For more information and examples, take a look at:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

NGINX: Rewrite url and reverse proxy to a different port

how to configure nginx as reverse proxy to different nginx running on different subnet with uWSGI?

How to use NGINX reverse proxy, and proxy the port and path to the upstream url?

How to listen to different port on Nginx and proxy the request?

Nginx reverse proxy for port 3001

How to configure NGINX as a reverse proxy in front of an AWS ALB

NGINX: How do I remove a port when performing a reverse proxy?

How to set up Nginx reverse proxy on the same port as the application?

How to configure Docker port mapping to use Nginx as an upstream proxy?

How to setup eureka clients behind reverse proxy with different port?

Nginx reverse proxy: How to get access to different container via subdomains?

Configure Nginx reverse proxy subdomains with dynamic DNS

Configure Reverse Proxy on NGINX with Grafana on Windows

Nginx Reverse Proxy with Port Forwarding Not Working

How to configure OwnCloud and Reverse Proxy?

How to create a reverse proxy on Nginx?

how to config nginx reverse proxy

Elasticbeanstalk Nginx Reverse Proxy Conf for Different Server

NGINX - Reverse proxy multiple API on different ports

Nginx reverse proxy with different context path

Jenkins: How to configure Jenkins behind Nginx reverse proxy for JNLP slaves to connect

How to configure a container with Apache for Drupal 8 behind another container Nginx used as a reverse proxy

How to configure NGINX correctly as reverse proxy for tine20 docker container (which runs with Apache2)?

How can I configure IdentityServer4 (DotNet Core) to work in Nginx reverse proxy

How do I fix nginx reverse proxy to a wordpress docker redirecting port for the user?

How to hide web application port in reverse proxy

Nginx reverse proxy inside docker not honoring port setting for upstream

Nginx Reverse proxy for a docker container running at port 80

Nginx redirect https->http(reverse proxy)->port(docker container)