1

There is a server running in a "remotehost:some_port". I can connect to it from my linux machine like telnet remotehost remoteport. I have an application in the linux machine that is configured to connect to 127.0.0.1:7576 where it expects the server to run. I can change the configuration to connect to remote server instead but is there a way to proxy the remote server so that I don't have to change the configuration? I can do ssh port binding (like ssh -L...) but the remote server does not ssh. Is there an easy way other than creating a process that listens on localhost and forwards the packets to the remote server?

balki
  • 123
  • 9

1 Answers1

1

One way to do this is to run a proxy locally, such as nginx. The documentation is pretty good with relevant examples.

Here is a minimal, yet more complete, example:

worker_processes auto;
error_log error.log;
events { }
stream {
  server {
    listen 127.0.0.1:7576;
    proxy_pass REMOTE_HOST:7576;
  }
}

Below is an example of running nginx in the foreground with the above configuration in a file named: nginx.conf.

nginx -p $PWD -c nginx.conf -g "daemon off; pid nginx.pid; error_log /dev/stderr;"

The -g option supplies global configurations. daemon off is the one that makes it run in the foreground. pid nginx.pid puts the pid file in the working directory since default puts it in logs directory that probably isn't there. error_log /dev/stderr send error logs to the console, I've found this is needed to be in the -g option when running with daemon off, otherwise it may try to log to the default location before reading the error_log configuration from the file.

virullius
  • 988
  • 8
  • 22
  • Does it work even if the server is not a http server? – balki Sep 28 '18 at 19:10
  • 2018/09/28 19:16:03 [emerg] 2277#2277: unknown directive "stream" in /home/bala/nginx.conf:4 – balki Sep 28 '18 at 19:16
  • nginx version: https://pastebin.com/raw/P8wZSjZ7 – balki Sep 28 '18 at 19:19
  • added load_module. Getting this error: nginx: [emerg] the invalid "proxy_pass" parameter in /home/bala/nginx.conf:8 – balki Sep 28 '18 at 19:25
  • I don't know what the `--with-stream=dynamic` does, but I just built nginx-1.14.0 with `./configure --with-stream && make` and ran it directly from the `objs` directory like so: `./nginx -p "$PWD" -c nginx.conf -g "daemon off; pid nginx.pid; error_log /dev/stderr;"` and it worked as expected. – virullius Oct 01 '18 at 15:10