blog image

Connecting your local web server to the Internet.

#localhost
#self-hosting
#open-source
#reverse-proxy

22 Aug 2024

When you’re developing a web application, you often need to test it on your local machine before deploying it to a public server. However, this can be challenging because your local development environment is not accessible from the internet. That’s where tools like localhost.run, ngrok and Cloudflare Tunnel come in handy.

What is localhost.run

localhost.run is a free, open-source tool that allows you to create a secure, public URL for your local web server. It works by setting up a reverse proxy that forwards traffic from the public URL to your local machine. This enables you to easily share your local development environment with others or test your application from different devices.

How does localhost.run work?

When you run the localhost.run command, it will provide you with a unique public URL (e.g., https://random-string.lhr.life) that you can use to access your local web server. The localhost.run service handles the routing and forwarding of traffic to your local machine, so you don’t have to worry about configuring firewalls or port forwarding.

localhost.run uses SSH (Secure Shell) as a client. All major operating systems already have SSH installed. To connect a random internet domain to an application running locally on port 8080 open a command terminal and run:

$

ssh -R 80:localhost:8080 nokey@localhost.run

Free tunnels change domain names after a few hours. To keep your domain name between connections you can refer to the documentation here.

Comparing localhost.run to ngrok and Cloudflare Tunnel

ngrok:

  • ngrok is a popular tool that also allows you to create a public URL for your local web server.
  • It offers more advanced features, such as the ability to capture and inspect HTTP traffic, create TCP/UDP tunnels, and even expose your local environment to the internet through a secure SSH connection.
  • ngrok has a free plan, but it also offers paid plans with additional features and higher limits.

Cloudflare Tunnel (formaly Cloudflare Argo Tunnel):

  • Cloudflare Tunnel is a service provided by Cloudflare that allows you to securely connect your local web server to the internet.
  • It uses the Cloudflare network to route traffic to your local machine, providing a secure and reliable connection.
  • Cloudflare Tunnel is free for personal use, but it also has paid plans for business with more advanced features.

Compared to these tools, localhost.run is simpler and more lightweight solution. It doesn’t have as many advanced features as ngrok, but it’s free and easy to use. Cloudflare Tunnel, on the other hand, is more focused on security and reliability, and it’s a good choice if you need a more enterprise-grade solution.

Example Use Cases for localhost.run

Sharing your local development environment: Share your local web application with colleagues, client, or stakeholders for a review and feedback without having to deploy it to a public server.

Testing web applications on different devices: Test your web applications on various devices (smartphones, tablets, etc.) by accessing the localhost.run URL from those devices.

Debugging and troubleshooting: Provide the localhost.run URL to a support team or developer to help then debug an issue with your local web application.

Prototyping and quick demos: Quickly create a public URL for your local web application to demonstrate a proof of concepts or prototype without having to set up a full deployment.

In summary, localhost.run is a simple and free tool that allows you to easily share your local web server with the world. While it may not have all the advanced features of ngrok or Cloudflare Tunnel, it’s a great option for many common use cases, especially if you don’t need the more complex functionality of those other tools.