Choosing Between ngrok HTTP and TCP Tunnels for Secure Local Web Service Exposure
Guide to choosing ngrok HTTP vs TCP tunnels for exposing a local web service with HTTPS, basic auth, and a stable subdomain, including a ready‑to‑use config and validation steps.
31 Jul 2026, 13:18 UTC

Decision and Constraints
You need to expose a local web service that must be reachable via HTTPS, protected with client‑side basic authentication, accessible through a stable subdomain, and introduce latency under ~100 ms for interactive use.
Option Comparison
| Option | Protocol | TLS Termination | Auth | Subdomain | Typical Latency | Setup Complexity | Free‑Tier Limits |
|---|---|---|---|---|---|---|---|
| HTTP | HTTP/HTTPS | Ngrok terminates TLS | Basic auth via ngrok config | Yes (reserved) | Low (~30‑70 ms) | Simple | 4 tunnels, 8 hrs/session |
| TCP | Raw TCP | None (client handles TLS) | App‑level or external | Yes (reserved) | Very low (<20 ms) | Moderate (manage certs) | 4 tunnels, 8 hrs/session |
Trade‑offs
The HTTP tunnel gives you automatic HTTPS and easy basic‑auth integration at the cost of slightly higher latency and reliance on ngrok’s TLS termination. The TCP tunnel offers lower latency and full control over encryption but requires you to manage TLS certificates and authentication yourself, increasing operational complexity.
Concrete Implementation (HTTP Tunnel)
Assuming your local service runs on port 8080 and you have an ngrok authtoken:
- Create a configuration file
ngrok.yml:
authtoken: YOUR_NGROK_AUTHTOKEN
tunnels:
web:
proto: http
addr: 8080
subdomain: myservice # reserved subdomain on your account
auth:
username: admin
password: secret
- Start the tunnel:
ngrok start --config ngrok.yml web
Ngrok will allocate a public URL like https://myservice.ngrok.io that terminates TLS at ngrok’s edge and injects the basic‑auth header before forwarding to your local service.
Validation Steps
- Open the inspector URL
http://127.0.0.1:4040in a browser; confirm the tunnel listshttps://myservice.ngrok.ioand shows the auth configuration. - From a terminal, test access with curl:
curl -u admin:secret https://myservice.ngrok.io
Expect a 200 OK response from your application. Verify that the URL’s subdomain matches the reserved value you set in ngrok.yml.
Limitations and Checks
- Free accounts limit each tunnel to 8 hours per session; after that the tunnel disconnects and must be restarted.
- Only four simultaneous tunnels are allowed on the free tier; additional tunnels require a paid plan.
- Because ngrok terminates TLS, you must trust ngrok’s certificate authority; if you need end‑to‑end encryption, consider the TCP option and manage your own certificates.
- To ensure the tunnel is still running, periodically check the inspector UI or run
ngrok status.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.