Build your own ngrok

This simple setup can help us expose our local development environment to the public internet. I usually paid for ngrok, but the last time I tried them, they were expensive, and their customer support was terrible.

For a small-size project, we can build our own small ngrok with Linux, Caddy, and SSH port forwarding.


  • A VPS with Linux. In this example, we will use Ubuntu 20.01 LTS
  • SSH access to your server
  • Caddy
  • A domain name. In this example, we will use

Add DNS record

We need to add two A records to our domain DNS zone:

  • An A record pointing to our server’s IP address
  • A wildcard A record pointing to our server’s IP address

For example, if our server IP address is, our records will look like this:

DNS records example

Configure Caddy

First, Install Caddy.

Then, create a Caddyfile to route traffic from a specific domain name to a local port; in this case, we will do and port 8881.

touch ~/Caddyfile {
  log {
    output file /var/log/access.log

Reload caddy.

caddy reload

> 2023/05/30 17:55:25.272 INFO    using adjacent Caddyfile

And our server is ready.

Create an SSH tunnel

With SSH, you can create a secure connection between your computer and the server, with the services relayed, i.e., every request to the server will be forwarded to your local development environment.

For example, if we are building our application in localhost:8000, we can do the following:

# ssh -R <server port>:<server domain>:<local port> <server ssh user>@<server domain>
ssh -R

Now, every request you send to will be forwarded to localhost:8000 on your computer.


No artificial intelligence was used in the making of this post.