Skip to content

Expose your local application as a public URL using ngrok

Learn how to expose your local application as a public URL using ngrok. You have developed an application and testing it in your local machine, but you want it to be accessed by someone who is at the other side of the world. You also do not have access to a cloud server with which you could deploy your application and give access to your friend. This is where ngrok comes into picture.

ngrok helps to take your application that is running in your local machine and expose it as a public URL which can be accessed by anyone who has internet access and use it. ngrok can expose your application with both http and https protocols. It doesn’t matter if your local app is in http or https.

ngrok allows you to expose a web server running on your local machine to the internet. Just let ngrok know what port your web server is listening on. Let’s see how to get this done.

Sign up on ngrok’s website

Log in to ngrok website with your account

Once you log in to your ngrok account, you will see the basic steps to setup ngrok.

Download ngrok

ngrok provides an easy to install binary with zero dependencies. Use curl to download it to your local machine.

curl https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip --output ngrok.zip

Unzip the binary

unzip /home/achandran/ngrok.zip

Add your account’s authtoken to ngrok.yml

The authtoken is specific to a user, so please copy it from your ngrok’s dashboard

./ngrok authtoken 1YFwlRLe4bFHTyYOWwpNZyuuiweyr786w7e86rwvd4tay18mt4K

Start a HTTP tunnel from the port

Just point ngrok to the port your application is deployed to. If you are not sure about the port, just point it to the default http port 80.

./ngrok http 8020

Once you run this command, ngrok will open an interface with details like your account, URL to which your local web server is exposed to the public and more..

ngrok by @inconshreveable                                                                                                                                                                    (Ctrl+C to quit)
                                                                                                                                                                                                             
Session Status                online                                                                                                                                                                         
Account                       Anand Chandran (Plan: Free)                                                                                                                                                   
Version                       2.3.35                                                                                                                                                                         
Region                        United States (us)                                                                                                                                                             
Web Interface                 http://127.0.0.1:4040                                                                                                                                                          
Forwarding                    http://6a6af1b9.ngrok.io -> http://localhost:8020                                                                                                                              
Forwarding                    https://6a6af1b9.ngrok.io -> http://localhost:8020                                                                                                                             
                                                                                                                                                                                                             
Connections                   ttl     opn     rt1     rt5     p50     p90                                                                                                                                    
                              0       0       0.00    0.00    0.00    0.00     

You copy the URL from this and access your application from anywhere. Eg: https://6a6af1b9.ngrok.io

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.