Accessing localhost From Anywhere
You’ve spent hours working locally on your computer, getting that new website design to look just right. Your CMS is nicely set up with sample content and you want to test it out on a few mobile devices and tablets. Your client also wants to take a look — but you don’t have time to migrate it all to a public server to give them a quick peek.
How is it Possible to Access localhost From Anywhere?
It is possible through secure tunnel services online! These are services that provide you with a tunnel from the internet to your machine.
What that means is that they provide a publicly accessible URL, watch for calls on that URL and forward those calls to your localhost server. All the confusing setup has been done for you — all you need to do is install an application and point it to your localhost.
ngrok
ngrok is an application for Windows, Mac OS X, and Linux that creates a tunnel but also allows you to inspect all traffic that goes through the tunnel and replay that traffic for testing.
You can use basic features for free and then sign up to access more advanced features. You install ngrok and run it. Nothing else is required.
How to use ngrok
Go to ngrok.com, download the archive and extract it to wherever you’d like ngrok to live on your computer.
Open up a command line terminal and go to the folder you extracted ngrok to. Run the following command to create a tunnel to your localhost on port 8
1
| ./ngrok 80
|
In the example above, we’ve got traffic to a randomly generated ngrok address of http://3dfab6bf.ngrok.com being forwarded to our localhost on 127.0.0.1:80.
Open that URL on any device with an internet connection and you’ll be accessing your localhost from the web!
One of the more unique offerings ngrok provides is the ability to inspect past traffic. To do that, go tohttp://localhost:4040/ on your computer.
ngrok’s Advanced Features
If you sign up to ngrok for free, you can use additional features such as:
Custom subdomains (so you don’t need to remember that randomly generated URL!). If you pay a bit to help keep ngrok running, you can reserve a subdomain so others can’t take it. The following allows you to view your localhost at nogophersinmytunnel.ngrok.com:
1
| ngrok -subdomain nogophersinmytunnel 80 |
Password protection to prevent random members of the public from accessing your site:
1
| ngrok -httpauth "username:password" 80 |
If you’ve paid a bit of money for ngrok, they’ll allow you to use your own domains, rather than needing to use ngrok.com:
1
| ngrok -hostname "tunnel.yourdomain.com" 80 |
You can even tunnel to an IP address on your local network that otherwise would not be accessible to the outside world:
1
| ngrok 192.168.0.27:80 |
Or create a tunnel for other non-HTTP services:
1
| ngrok -proto=tcp 22 |
PageKite
PageKite is a Python-based “dynamic tunnel based reverse proxy” that works on Windows, Mac OS X, Linux, and even Android devices! It is very similar to ngrok but has been around for quite a bit longer and appears quite a bit more battle-tested for a larger set of uses. They’ve even got it working with the Minecraft protocol to allow people to run a Minecraft server on their local machine.
You can sign up for a free trial for a month. After that it has a pay-what-you-want system. You do need to pay more to get more in this case though, with those paying larger amounts getting a larger quota, a longer term of service, custom subdomains, and so forth.
PageKite doesn’t appear to have a traffic inspector like ngrok but it does have rather incredible features like anAndroid app that allows you to use the same PageKite tunnelling on your Android device.
How to use PageKite
Go to PageKite.net and download the version for your OS. For Windows users, you’ll need to make sure you have Python installed first. For Mac OS X and Linux, you can use a simple curl command to install it straight from your command line.
Once downloaded, run this command to run a tunnel to your localhost server. You choose a specific subdomain which you use each time (rather than the random allocation in ngrok). I’ve chosen
quickgetintothetunnel
here:
1
| pagekite.py 80 quickgetintothetunnel.pagekite.me |
A few of the impressive additional features PageKite has are:
No need for a web server. If you don’t have a server running, it has an inbuilt web server that can run your static files like this:
1
| pagekite.py /path/to/folder igotthattunnelvision.pagekite.me |
Like ngrok, you can restrict access via password:
1
| pagekite.py 80 terelekkayatuneli.pagekite.me +password/username=password |
Forward
Forward is a tunneling service that runs on Ruby and works on Windows, Mac, and Linux. It has a stronger focus on using the service to show clients work in progress and so includes features such as setting placeholder pages for when the tunnel is turned off and ensuring robots.txt is off to ask our friendly search engines not to index it.
Forward has a free 30-day trial and then has monthly plans for individuals, small businesses, and larger businesses.
How to use Forward
Sign up for an account at forwardhq.com. When signing up, you provide the initial URL that you’d like to use on the service (similar to PageKite). I set mine up to forward to patcat.fwd.wf. Make sure you’ve got Ruby and Rubygems installed on your computer!
Install the Forward gem. I needed to use sudo for it to work successfully on my Mac:
1
| sudo gem install forward |
In order to start a tunnel to your localhost on port 80 you run this command:
1
| forward 80 |
ProxyLocal
ProxyLocal appears to be a much smaller-scale tunneling service that runs on Ruby. It is completely free and could be a good budget option for students and those needing a tunneling service very infrequently.
It has less features but does the job well. It doesn’t require sign up to run it either, which is pretty quick and convenient!
How to Use ProxyLocal
Install the ProxyLocal gem. Just as with Forward I needed to use sudo for it to install successfully on my Mac:
1
| sudo gem install proxylocal |
To get a tunnel to your localhost on port 80 running use the command:
1
| proxylocal 80 |
The only other option it provides is custom hostnames. The below command would set our tunnel URL to lightattheendofthe.t.proxylocal.com:
1
| proxylocal 80 --host lightattheendofthe |
BrowserStack
BrowserStack provides provides automated screenshots and virtual machines to test your website against a range of devices and browsers. If the reason you’re wanting to access localhost is for testing, BrowserStack might be of interest to you.
You can use the above methods to test localhost sites in the BrowserStack virtual machines, however it also has a browser extension for Chrome and Firefox allowing you to provide access to your localhost from their servers.
How to use BrowserStack
Sign up for a trial at BrowserStack.com. They’ve actually got the process of local testing documented quite well on their website, so have a read of that if you’re interested in going this route.
In the end though, it’ll allow you to test your localhost sites in virtual machines run over the web like so:
Conclusion
If you’re working on a computer with an active internet connection, you can now set up access to your localhost from anywhere in only a few minutes! It’s incredibly simple to get started and, as you can see… there’s no shortage of solutions!
Have you used any of these services? Do you have any others you prefer? I’d love to know your thoughts in the comments below!
No comments:
Post a Comment