DEV Community

Cover image for Fix Ngrok tunnel not working with error: This site can’t be reached
Stephen Akugbe
Stephen Akugbe

Posted on

Fix Ngrok tunnel not working with error: This site can’t be reached

Ngrok is a powerful tool that allows you to expose local servers to the internet, making it an invaluable asset for web development and testing. Creating a tunnel with Ngrok enables you to share your localhost environment globally. However, users sometimes encounter issues, with one common problem being the "This site can't be reached" error. In this post, we'll explore how to create a tunnel with Ngrok, understand what Ngrok is, and finally, address the tunnel-related error.

What is Ngrok?
Ngrok is a secure tunneling platform that establishes secure connections between local servers and the internet. It acts as a middleman, allowing you to expose your local server to the wider web, making it an indispensable tool for developers working on web projects.

Creating a Tunnel with Ngrok:
To create a tunnel using Ngrok, follow these steps:

Download and Install Ngrok:
Start by downloading Ngrok from the official website https://ngrok.com/download. Once downloaded, extract the archive and place the executable in a directory of your choice.

Navigate to the Directory:
Open a command prompt or terminal window and navigate to the directory where you placed the Ngrok executable.

Run Ngrok:
Use the following command to create a tunnel for your local server:
ngrok http PORT

Replace "PORT" with the port number your local server is running on.

Access the Tunnel:
Ngrok will generate a public URL that you can use to access your local server from anywhere. Look for the "Forwarding" section in the Ngrok console to find the provided URL.

Fixing the "This site can't be reached" Error:
If you encounter the "This site can't be reached" error while trying to access your Ngrok tunnel, it may be due to incorrect tunnel configurations. Make sure to include the --host-header option with the correct host and port. The command should look like this:

ngrok http PORT --host-header="localhost:PORT"

By specifying the host header, Ngrok can properly route requests to your local server, resolving the connectivity issue and allowing you to access your tunnel without encountering the error.
You might have to run the command a few times, but it'll definitely work.

I hope this helps you fix
P.S. This is also an archive for me to refer to later on.

Top comments (0)