Search code examples
nginxsshproxyvagrantportforwarding

SSH forward port to local host name


I have next setup:

  • Local host - my work PC
  • Project VM - Vagrant box with project files, runned on my work PC
  • Remote host - remote PC, from which I need to access hosts on Project VM

Project VM setup (/etc/hosts on Local host):

192.168.100.102 host1.vm.private
192.168.100.102 sub1.host1.vm.private
192.168.100.102 sub2.host1.vm.private

"host1" subdomains resolved by application router and served by nginx (config for "host1.vm.private" on Project VM):

server {
    listen 80;
    server_name ~^(.+\.)?host1\.vm\.private$;
    ...
}

I need to make "sub(1|2|N).host1.vm.private" reachable from remote host. How this can be done?


Solution

  • So, i found the solution: Trouble SSH Tunneling to remote server

    The main issue is that invalid HTTP header was sent and nginx cant resolve a virtual host.

    1. Run on local PC ssh -R 8888:192.168.100.102:80 <remote_pc_credentionals>. Or, run "inversed" command with ssh -L flag on remote PC.

    2. Add "sub1.host1.vm.private" to /etc/hosts on remote PC: 127.0.0.1 sub1.host1.vm.private

    OR

    1. Send "Host" header with each request: curl -H "Host: sub1.host1.vm.private" "http://localhost:8888/some/path"