Sometimes you need to show your project to your colleagues, interviewer or whoever. When you serve your project in a local network, you need to type the IP address and the port. If you want your project to be accessed over the Internet, http://public_ip:port
doesn’t work, as usually your computer is behind the NAT, which means you should provide port forwarding, but it can be not easy and sometimes Internet Service Providers do not allow change the settings. You can avoid potential problems with configuring your network if you use ngrok.
Ngrok is a service that creates a tunnel to your computer and generates an URL that you can share to access your service or files.
To install and run ngrok on Linux you can go through the following steps (do not forget to specify your_port):
mkdir ngrok
cd ngrok/
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
./ngrok http your_port
That’s it! Now all you need is to expose your project to the same port.
As an example, I’m going to use python’s http.server
to show a prototype API.
To serve your folder type python -m http.server your_port
within the directory. You’ll get a message:
Serving HTTP on 0.0.0.0 port your_port (http://0.0.0.0:your_port/) …
Now you can share the temporary domain shown in the screenshot above. Using this domain, your folder can be accessed from other machines, not necessarily connected to your local network. If there is an index.html file, you will see the corresponding web page; otherwise, the contents of the directory. I am exposing a simple service that processes 2 parameters to get a prediction:
So, to serve your folder/project over the internet you need:
- To start a local server (e.g., using python.server)
- To start ngrok using the port that your server is listening on
Note, that this approach has no built-in security and data protection features. Consider using TLS/SSL or a VPN connection if you need some more security.
Read the documentation to find more details.