Ssh – Tunnel requests from web server to the local machine for specific virtual hosts

apache-2.2sshssh-tunnel

I want that all http/https requests that come to a server for a particular virtualhost to be tunneled to my local machine.

Say my apache server has a virtualhost dev.nands.com, I would want all http/https requests coming to this virtualhost to be tunneled to my local machine. Other virtual hosts in the server should not be tunneled.

How can I do this ?

Best Answer

Set up your SSH tunnel to forward a local port on the web server to your system's web service (pick an unused port where I've used 8080):

ssh user@system.domain -R 8080:127.0.0.1:80

Then, set up a vhost that'll send requests to the new local port on the web server.

<VirtualHost *:80>
    ServerName dev.nands.com
    ... (logging config, access controls, etc)
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>