Can I use an SSH tunnel to access a web server that's listening on a different IP/Port on the same server?

8,739

Solution 1

I know cherokee management works this way, so let's say you have bound your webserver to your localhost on port 8080

ssh -L 8080:localhost:8080 your_servers_ip

After that you can access the remote interface through http://localhost:8080 and every request will be forwarded to the remote IP running your webserver.

Solution 2

What Lucas said, where "localhost" can also be any reachable IP address from the SSH host.

Note that if you're using name virtual hosts, you will also need to do a /etc/hosts hack, so that you append something to the existing 127.0.0.1 line, something like:

127.0.0.1   localhost  secretwebserver.example.com

Your browser can then use http://secretwebserver.example.com:8080.

Share:
8,739

Related videos on Youtube

Mike B
Author by

Mike B

Technology Enthusiast, Gamer, Sci-Fi Addict, and DIY-er in training. =)

Updated on September 18, 2022

Comments

  • Mike B
    Mike B over 1 year

    I've got a web server that isn't quite ready for general availability but I'd still like to test some things remotely. Can I leverage an SSH tunnel to connect to the server and then use the tunnel to route to the web service that is operating on the same server? If so how?

    I realize that implementing firewall exceptions would be easier but that isn't an option at this time.

    Sorry if this is confusing. I agree that it's a unique scenario.

    CentOS 5.x

  • Mike B
    Mike B over 12 years
    Thanks. On a side note, I also needed to modify my hosts file to leverage the address (as expected).