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 -

  1. Download ngrok binary from here

  2. Unzip the downloaded file

  3. To see various commands available, you may run ./ngrok help command.

  4. 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!

on twitter to get updates on new posts.

Stay updated!

On this blog, I post articles about different technologies like Java, MuleSoft, and much more.

You can get updates for new Posts in your email by subscribing to JavaStreets feed here -


Lives on Java Planet, Walks on Java Streets, Read/Writes in Java, JCP member, Jakarta EE enthusiast, MuleSoft Integration Architect, MuleSoft Community Ambassador, Open Source Contributor and Supporter, also writes at Unit Testers, A Family man!