Skip to main content
This guide provides an example of using an ngrok Cloud Endpoint to route traffic between multiple internal endpoints.

Core concepts

  • Cloud Endpoints are centrally managed endpoints in the cloud that you can use to route traffic to Agent Endpoints.
  • Internal endpoints are endpoints that are not publicly accessible and are only reachable from within your network by Cloud Endpoints via the forward action.
  • Load balancing improves application performance and reduces load by distributing incoming traffic across servers. This leads to faster response times for user-facing applications.

Prerequisites

To follow this guide, you need a local computer with ngrok installed. You can download ngrok here. If you’re following along using the ngrok CLI, you need: If you’re following along using CURL, you need:
  • An ngrok API key as an environment variable named NGROK_API_KEY.
1

Create an internal endpoint

Start by creating an internal endpoint, initiated from the agent. The endpoints use HTTP in this guide, but you can also use TCP or TLS.
After running the above command, you should see an internal endpoint with an “online” status for your domain. This endpoint routes traffic to the app running at your local port 80. You can set up any HTTP server to run on this port locally, and the endpoint internally routes traffic to that server.
2

Create a domain

Next, create the domain that the Cloud Endpoint resides on. For the purpose of this guide, create an ngrok HTTP domain.
  • Replace or set ${NGROK_SUBDOMAIN} as the subdomain you’d like to use for this guide.
After running, you should see the following:
skip-validation
When you have completed this step, you can move on to the next step.
3

Create a Traffic Policy for your Cloud Endpoint

Unlike Agent Endpoints in which Traffic Policies are optional, Cloud Endpoints require a Traffic Policy so they know how to handle incoming traffic. This guide shows one of the simplest and most common use cases: forwarding traffic to other endpoints (the internal endpoint you created in Step 1) via the forward action.
4

Create an ngrok Cloud Endpoint

Now create an ngrok Cloud Endpoint that points to the newly created internal endpoint. You can create Cloud Endpoints via the API or the ngrok dashboard.
Use the URL from Step 2 as the url value in the Traffic Policy, and the Traffic Policy from Step 3 as the traffic-policy value. This command sets the binding to public so anyone can access the Cloud Endpoint.
  • Replace NGROK_SUBDOMAIN with the value you used in Step 2.
5

Load balancing with Endpoint Pools

Load balancing is simple with ngrok Endpoint Pools. Start another agent with the same internal endpoint URL, and ngrok automatically load balances traffic between the two agents in the pool.

Conclusion

You’re done. You’ve successfully created a Cloud Endpoint that you can access from the URL you reserved: ${NGROK_SUBDOMAIN}.ngrok.app The Cloud Endpoint refers to its Traffic Policy and forwards traffic to the internal endpoint. The internal endpoint finally exposes the local port you created it on in Step 1.