As has been discussed, ssh -L 8080:localhost:80 username@server.com
doesn't start a magic proxy server on the client side, it simply forwards client port 8080 to server port 80. You need to get the client web browser to connect to client port 8080, which as others and myself have said involves pointing your client web browser at http://localhost:8080/
.
Your new problem is that the server is running a number of name-based virtual hosts, and you don't get the right host served to you when you don't request it from the server in the URL, which is reasonable enough.
The simplest workround is to tell your client to access the site by name, but to get the OS to lie to the browser about what IP address that host resolves to. Let us suppose that you want to access hosts vsite1.example.com
and vsite2.example.org
, which are both being served on port 80 on server, via the SSH tunnel we have already set up.
Edit your client-side /etc/hosts
file to tell your OS that those hostnames resolve to 127.0.0.1
, with entries such as
127.0.0.1 localhost localhost.localdomain vsite1.example.com vsite2.example.org
I believe there are corresponding hacks for Windows, but I don't know what they are, as I never use it.
Now you can point the client browser at http://vsite1.example.com:8080/
, the client OS will tell the browser that's on localhost, the URL will point the browser to localhost port 8080, ssh will conduct the packets sub rosa to server port 80, and client browser will ask server's web server for the right vhost.