1
  • I have a computer (let's call it A) on a local network with no static IP address accessible from the outside. (SSH port AAAAA)
  • A has a webserver that I want to be able to access from the outside
  • I have a server (B) accessible from the internet, that also runs a webserver (ssh port: BBBBB)
  • I want to be able to access the webserver on A through B from any computer with a web browser.

I have been using SSH remote tunnelling successfully with the following setup:

  • on the machine A:

    $> ssh -f -N -p BBBBB -R 0.0.0.0:9000:localhost:AAAAA userB@B.B.B.B

  • on the machine C:

    $> ssh -f -p 9000 -D 9001 -N userA@B.B.B.B

  • on the web browser of machine C, manual proxy configuration SOCKS host: localhost, port 9001, SOCKS v5

This works really well, but it's very tiedous to have to launch the SSH command on C, and change the settings in the web browser every time...

So I talked about this to someone, who told me that I could probably simplify the setup by having the part done on machine C directly done on the server B, with some web config in nginx on B's webserver. So now, I tried this:

  • On A, same as before
  • on B:

    $> ssh -f -p 9000 -D 9001 -N userA@127.0.0.1

  • on B's nginx config:

    $> cat /etc/nginx/sites-available/default:

upstream tunnel {
    server 127.0.0.1:9000;
}

server {
        listen 80;
        [...]
      location /A {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        proxy_pass http://tunnel;
  }
    [...]
}
server {
        listen 443 ssl;
        [...]
      location /A {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://tunnel;
  }
    [...]    
}

To my understanding, from a web browser on a machine connected to internet, requesting http://B.B.B.B/A should tunnel to 127.0.0.1:9000 which is the forwarded port for my machine A, thus giving me access the the webserver on A.

Something is wrong in this setup though, as when I try to connect to http://B.B.B.B/A I get a long loading time (about a minute) followed by a blank page, with the following error message written on it:

SSH-2.0-OpenSSH_6.7p1 Raspbian-5+deb8u3
Protocol mismatch.

I google'd that error a little bit, and found a few posts with relatively similar issues, but honestly, with my (very) limited skills in this kind of stuff, I'm lost when trying to project their fix to my use case... Could anyone help me?

  • You may try reverse proxy for your web server using nginx – Md Shahed Hossain Jun 23 '18 at 8:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.