In this tutorial
Exposing a local server to the internet is something every back-end developer needs sooner or later:
- Testing webhooks. Payment providers such as Paystack and Flutterwave, and services like GitHub and Slack, send events to a public URL. They cannot reach
localhost. - Testing a mobile app on a real phone against the API running on your laptop.
- Sharing work in progress with a teammate or client without deploying it.
The tricky case is when your local server already uses HTTPS, for example a Spring Boot app configured with a self-signed certificate on https://localhost:8443. Here is a step-by-step guide to doing this for free.
How tunnelling works
A tunnelling tool runs a small agent on your machine. The agent opens an outbound connection to the tool’s cloud service, which gives you a public HTTPS URL. Requests to that URL travel through the tunnel to your local server, and responses travel back the same way. Because the connection is outbound, you do not need to change router settings or open firewall ports.
Option 1: ngrok
ngrok is the best-known tunnelling tool, and its free plan is enough for development and testing.
Step 1: Install ngrok
Download ngrok from the official website and follow the instructions for your operating system, or install it with a package manager:
# macOS
brew install ngrok
# Windows
choco install ngrok
Step 2: Connect your account
Sign up for a free account, copy your auth token from the ngrok dashboard and run:
ngrok config add-authtoken YOUR_AUTH_TOKEN
You only need to do this once per machine. Keep the token secret; anyone who has it can open tunnels on your account.
Step 3: Start a tunnel to your HTTPS server
For a plain HTTP server, ngrok http 8080 is enough. When your local server already speaks HTTPS, pass the full URL, including the scheme:
ngrok http https://localhost:8443
ngrok terminates the public HTTPS connection with its own trusted certificate, then connects to your local server over HTTPS. It does not verify self-signed local certificates, so your development certificate works without any extra setup.
Step 4: Use the public URL
ngrok prints something like:
Forwarding https://abc123.ngrok-free.app -> https://localhost:8443
Use that https://...ngrok-free.app URL as your webhook endpoint, or open it on your phone. ngrok also runs a local inspection dashboard at http://127.0.0.1:4040. It shows every request and response passing through the tunnel and lets you replay a request, which is invaluable when debugging webhooks.
Option 2: Cloudflare Tunnel
Cloudflare’s cloudflared tool offers free “quick tunnels” that need no account at all:
cloudflared tunnel --url https://localhost:8443 --no-tls-verify
It prints a random https://...trycloudflare.com URL. The --no-tls-verify flag is needed because your local certificate is self-signed. Quick tunnels are great for short tests; for a permanent hostname you set up a named tunnel with a Cloudflare account.
Example: receiving a webhook in Spring Boot
Here is a minimal controller to receive and log webhook events while you test:
@RestController
@RequestMapping("/webhooks")
public class WebhookController {
private static final Logger log = LoggerFactory.getLogger(WebhookController.class);
@PostMapping("/payments")
public ResponseEntity<Void> payment(@RequestBody String payload,
@RequestHeader Map<String, String> headers) {
log.info("Webhook received: {}", payload);
// TODO: verify the provider's signature header before trusting the payload
return ResponseEntity.ok().build();
}
}
Point your provider’s test-mode webhook URL to https://<your-tunnel>/webhooks/payments, trigger a test event and watch it arrive in your logs and in the ngrok inspector. New to Spring Boot? Start with Build your first REST API with Spring Boot.
Things to consider
- Make sure your local server is running and reachable on the port you specified before starting the tunnel. A “502 Bad Gateway” from ngrok usually means nothing is listening locally.
- Security: anyone who knows the URL can reach your machine. Do not expose admin panels, databases or production data. Stop the tunnel when you are done. For sensitive testing, ngrok can add basic authentication (
--basic-auth "user:password") or restrict access in other ways. - Verify webhook signatures. Payment providers sign their webhook requests. Always check the signature so a stranger who discovers your URL cannot send fake “payment successful” events.
- Free plan limits: ngrok’s free plan limits things like bandwidth and the number of tunnels, and shows a browser warning page on HTML requests. Most free plans now give you one static domain you can reuse, which saves you from updating webhook settings every time you restart. Check the current plan details on the ngrok website.
- Host header problems: some frameworks reject requests whose
Hostheader does not match. If you see this, try--host-header=rewritewith ngrok.
Summary
- Install ngrok and add your auth token.
- Run
ngrok http https://localhost:PORTto tunnel to a local HTTPS server. - Use the public HTTPS URL for webhooks, mobile testing or demos, and inspect traffic at
127.0.0.1:4040. - Prefer Cloudflare quick tunnels if you want no sign-up.
- Keep tunnels short-lived, protect sensitive endpoints and verify webhook signatures.
By following these steps, you can get a public HTTPS address for your local HTTPS server for free, which makes external integrations and testing much easier.