Skip to main content

Full example

Below is a comprehensive configuration file for ngrok with detailed documentation for each option. To activate a specific option or tunnel, simply uncomment the relevant lines by removing the # at the beginning of the line.

Tunnel configurations

The most common use of the configuration file is to define tunnel configurations. Defining tunnel configurations is useful because you may then start pre-configured tunnels by name from your command line without remembering all of the right arguments every time. You may also use this method to start as many tunnels as you like from a single ngrok agent. Tunnels are defined as mapping of name -> configuration under the tunnels property in your configuration file.
Define two tunnels named ‘httpbin’ and ‘demo’
Start the tunnel named ‘httpbin’
Each tunnel you define is a map of configuration option names to values. The name of a configuration option is usually the same as its corresponding command line switch with hyphens (--host-header becomes host_header: in the configuration file and --url becomes url). Tunnels can define a specific proto or use labels to dynamically connect to one or more matching ngrok Edges. All tunnels must define a specific addr that tells the agent where to send the traffic. Other properties are available and many are protocol-specific.
Start all tunnels defined in the configuration file
You can configure a single ngrok agent to tunnel to multiple services within a single agent session.
Common tunnel configuration properties

HTTP configuration

TCP configuration

TLS configuration

Labeled tunnel configuration

Define two labeled tunnels
When you use labeled tunnels, the protocol and domain are configured by the matching edge.
Edges automatically create an edge label, for example: edge=edghts_2gYaK9XAVa3ANouaDEPrkeaxkYT

Agent configuration

The following is a list of options that can be configured at the root of your configuration file and specify the behavior of the agent.

api_key

This option specifies the API key used to access the ngrok API through the ngrok api command. This is only needed when using the ngrok API and not the local ngrok agent API (available at localhost:4040/api). You can generate an API Key in the ngrok Dashboard and install it using the ngrok config add-api-key command.
ngrok.yml specifying an API key

authtoken

This option specifies the authentication token (sometimes called tunnel credential) used to authenticate this agent when it connects to the ngrok service. After you’ve created an ngrok account, your dashboard will display the authtoken assigned to your account. Your authtoken will work on multiple machines if you are just developing. When you want to deploy many agents on many devices, you can generate a unique authtoken for each device in the ngrok Dashboard or via the ngrok api credentials command.
ngrok.yml specifying an authtoken

connect_interface

Sets the specific network interface that the ngrok agent should use. This is only supported on Linux platforms.

connect_timeout

How long to wait when establishing an agent session connection to the ngrok service. This is specified as a duration, with the default being 10s.

console_ui

This option allows you to enable or disable the console UI that is displayed in your terminal window after starting ngrok.

console_ui_color

The command sets the background color when displaying the console UI in the terminal. To choose a color other than black, set the value to transparent and change the background of your terminal window.

crl_noverify

This option will skip verifying with the Certificate Revocation List if set to true. This defaults to false.

dns_resolver_ips

Consult these DNS servers for tunnel session DNS resolution. By default, the ngrok agent will use the local system DNS servers to resolve.

heartbeat_interval

How often the ngrok agent should heartbeat to the ngrok servers defined as a duration. The default is 10s.

heartbeat_tolerance

Reconnect the agent tunnel session if the server does not respond to a heartbeat within this tolerance defined as a duration. The default is 15s.

inspect_db_size

This is the upper limit in bytes on memory to allocate when saving requests over HTTP tunnels for inspection and reply. The default is 0, which means 50MB.

log_level

This is the logging level of detail. In increasing order of verbosity, possible values are: crit, warn, error, info, and debug.

log_format

This is the format of written log records.

log

This is the destination where ngrok should write the logs.

metadata

This is a user-supplied custom string that will be returned as part of the ngrok API response to the list online sessions resource for all tunnels started by this agent. This is a useful mechanism to identify tunnels by your own device or customer identifier. Maximum 4096 characters.

proxy_url

This is the URL of an HTTP or SOCKS5 proxy to use for establishing the tunnel connection. Many HTTP proxies have connection size and duration limits that will cause ngrok to fail. Like many other networking tools, ngrok will also respect the environment variable http_proxy and http_proxy_env if it is set.

region

Deprecated This is the region where the ngrok agent will connect to. You can only choose one region per agent session. Choosing the region closest to you usually improves latency and performance. By default, the ngrok agent attempts to choose the best region for you.

remote_management

Set this to true to allow the ngrok agent to be remotely managed (stop, restart, update) via the ngrok API or the ngrok Dashboard. Defaults to true.

root_cas

This is the root certificate authorities used to validate the TLS connection to the ngrok server.

server_addr

This is the URL of the ngrok server to connect to. You should set this if you are using a custom ingress URL.

tunnels

This is a map of names to tunnel definitions. See tunnel definitions for more details.

update_channel

The update channel determines the stability of released builds to update to. Use ‘stable’ for all production deployments.

update_check

This tells the ngrok agent if it should check for updates. Defaults to true.

version

Specifies the version of the config file to use.

web_addr

This is the network address to bind on for serving the local agent web interface and API.

web_allow_hosts

These are a list of specifiers for what Host headers will be allowed to make requests agains the local agent web interface and API. Any port is stripped off the Host header before matching is performed.
Allow an IP address and a domain as Host headers