Server

Ngrok

What is Ngrok?

Ngrok is a multi-platform tunnelling, reverse proxy software that establishes secure tunnels from a public endpoint to a locally running network service. It is a great tool for testing webhooks, APIs, and other services that require a public URL.


Installation

macOS

$ brew install ngrok

Linux

$ sudo apt install curl
$ curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
	| sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null \
	&& echo "deb https://ngrok-agent.s3.amazonaws.com buster main" \
	| sudo tee /etc/apt/sources.list.d/ngrok.list \
	&& sudo apt update \
	&& sudo apt install ngrok

Raspberry Pi

$ snap install ngrok

Uninstallation

Linux

$ sudo apt remove --purge ngrok -y
$ sudo rm /etc/apt/sources.list.d/ngrok.list

Remove the repository key:

$ sudo rm /etc/apt/trusted.gpg.d/ngrok.asc

Update the package list to ensure the repository is completely removed:

$ sudo apt update

Remove configuration files if any exist:

$ rm -rf ~/.ngrok2

Configuration

$ ngrok config add-authtoken ***********************
$ nano ~/.config/ngrok/ngrok.yml
version: "3"
agent:
    authtoken: ***********************
tunnels:
  default:
    addr: 80
    proto: http

Service

You can create a service to start Ngrok automatically when the system boots.

$ sudo nano /etc/systemd/system/ngrok.service
[Unit]
Description=Ngrok
After=network.service
ConditionFileIsExecutable=/usr/local/bin/ngrok

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/usr/local/bin/ngrok start --all --config="/home/ubuntu/.config/ngrok/ngrok.yml"
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target

Once you have the service file created, you need to reload daemon and start the service.

$ sudo systemctl daemon-reload

Enable and start the service.

$ sudo systemctl enable ngrok
$ sudo systemctl start ngrok
Previous
Nginx
Next
PM2