Wednesday, December 28, 2011

Cheap, easy way to make your dev server available on the public internet.


While solutions like localtunnel and showoff.io allow you to do this, they have some limitations both in terms of cost and functionality. The biggest problem is that it gets expensive for lots of developers or you can't use your own hostnames.

We've developed a alternative using DNS, a reverse proxy and an ssh tunnel that makes it trivial to allow public access to a any number of dev servers on demand.

Here's how it works:
  • Set up a reverse proxy (you can use Apache or nginx).
# assume public IP of 1.2.3.4 # need name-based virtual hosting # so we can support many dev boxes with a single IP NameVirtualHost 1.2.3.4:80 # Need a VirtualHost container for each developer <VirtualHost 1.2.3.4:80> ServerName jason.dev.domain.com ProxyRequests Off ProxyPreserveHost On ProxyPass / http://localhost:2000/ ProxyPassReverse / http://localhost:2000/ </VirtualHost> <VirtualHost 1.2.3.4:80> ServerName tim.dev.domain.com ProxyRequests Off ProxyPreserveHost On ProxyPass / http://localhost:2001/ ProxyPassReverse / http://localhost:2001/ </VirtualHost>
  • Configure a wildcard CNAME record for *.dev.domain.com that points to your proxy server. Using the wildcard avoids having to munge DNS for every new developer.
  • Set up a proxy user account on the box and add all developers' ssh keys to the account. All this user needs to do is to log in and forward non-privileged ports, so it can be locked down substantially.
  • Edit your /etc/hosts to so that the canonical name for your server points to your local dev IP.
# /etc/hosts entry 33.33.33.11 jason.dev.domain.com
  • To make your dev server publicly available, create an SSH tunnel. Remember that each developer will have a particular remote port number assigned to them and them only.
ssh proxy@proxy.dev.domain.com -R 2000:jason.dev.domain.com:80
  • This setup allows the exact same host name to be used everywhere but have it hit the local dev box locally and have the same name resolve to the public proxy for development that require it.
While this does require you to have a publicly-reachable server somewhere to configure the proxy, this probably isn't a huge problem for most companies. In return you get a near foolproof setup for debugging webhooks, mobile apps, etc, at no cost, and without jumping through any hoops or relying on any third-party systems.