Exposing localhost site to Internet
We all run applications on local server and sometime we may want to expose sites running on localhost to internet for various reasons like demo or to see how external url’s will work or test integration with external tools. Deploying applications to remote server may not be possible for every scenario.
While working on javastreets.com, I wanted to test how the twitter cards will look like. Twitter has a validation tool but obviously it does not work for localhost url. So I was looking for a way to expose site running on localhost to internet.
A quick search on google, revealed a very handy tool ngrok.
|I have not verified how secure this is, so please use it wisely and at your own risks as you are essentially exposing your local network to internet. Please read through all ngrok documentation before using it.|
Using ngrok, it is very easy to expose localhost to internet, here are the steps -
Download ngrok binary from here
Unzip the downloaded file
To see various commands available, you may run
To expose a site that is running on
localhost:8820, run command
./ngrok http 8820. This will print console output like below and should have a unique url for your site.
ngrok by @inconshreveable (Ctrl+C to quit) Session Status online Version 2.2.8 Region United States (us) Web Interface http://127.0.0.1:4040 Forwarding http://88d12c8e.ngrok.io -> localhost:8820 Forwarding https://88d12c8e.ngrok.io -> localhost:8820 Connections ttl opn rt1 rt5 p50 p90 0 0 0.00 0.00 0.00 0.00
In above example, localhost site was accessible at url specified with forwarding field.
Then I was able to use this url in twitter card validator and it worked perfect.
|You may wish to read this hacker news discussion to know more views about this tool.|
Hope this helps you to test your localhost site on internet!
I usually post about Java, Java EE, Integrations, Mule ESB and other things in java ecosystem.
Get updates for new Posts in your email by subscribing to JavaStreets feed here -