Sometimes when working with a new web site I have customers who want to see the
site while it is still in development. One way of doing this
is to have alternative demo servers where all we do is just serve up our work
in progress. This works fine most of the time, but sometimes I just want to be
serve up my local machine.
Localtunnel
One easy way to do this is to use localtunnel.
localtunnel is a Ruby gem that is meant for exactly this purpose. Here's how:
It is now possible to access localhost:80 via the URL
http://4xiw.localtunnel.com. Simple as pie!
But what if you don't like pie? Or Ruby, for that matter. Or, what if you don't
like to serve your secret data through another company (Twilio in this case who
graciously gives away the hosting for free).
Well you are in luck, it is easy to set up your own tunnel via SSH, provided
you have access to a server that is accessible from the Internet. And,
everybody has access to such a server via Amazon EC2 or similar service. Make
sure the server is accessible on all high ports. On Amazon this is done by
opening all incoming ports above 1024 in a security group.
Setting up a tunnel via SSH
In SSH lingo a tunnel from an external server to my local server is called a
reverse proxy. Here is how to set one up. First you need to configure the
remote ssh daemon to allow setting up remote interfaces. A remote interface is
one that can be accessed from a server other than localhost, which is what we
want.
Here is how to do it, the server called host.amazonaws.com is my AWS server.
Now you are good to go. We assume you have a server running on port 3000 to
display to the world.
Now you can surf to http://host.amazonaws.com:34070
And it will access your local machine. :)
When you stop the command (Ctrl-C) the tunneling will stop.
Command explanation
If you want to simplify it for yourself add the following script to a bin
catalog.
Now all you have to do to enable remote access is tunnel 80, or whatever port
you want to display.
Escaping the proxy Jail
The story could have ended here, but some people, trapped behind corporate
firewalls, may not be allowed to use ssh. The traffic is blocked by a
corporate proxy server. Well, there is a happy ending for you too and it is
fittingly called corkscrew. It allows you
to screw yourself out of the corporate jail and into the world.
Here is how you do it on Ubuntu, on OS X use brew instead.
%h and %p is filled in by ssh with the host and port of your destination.
Freedom’s just another word for nothing left to lose,
Nothin’ don’t mean nothin’, honey, if it ain’t free.
Yeah, feeling good was easy, Lord, when he sang the blues,
You know feeling good was good enough for me,
Good enough for me and my Bobby McGee.