ngrok http 80.
Once your endpoint is running, check out:
- Traffic Policy - Add routing, authentication and traffic transformation
- Traffic Inspector - Real-time observability with request/response introspection
- Endpoint Pooling - Load balancing
Quickstart
Cloud endpoints are persistent and live until they are deleted. They are created via the ngrok dashboard or API. Traffic Policy controls how a Cloud Endpoint handles traffic. See the Cloud Endpoints Quickstart for a step-by-step guide on how to create a Cloud Endpoint in the ngrok dashboard. The following example uses the API to create a Cloud Endpoint which returns aHello world! 200 OK response.
Command line
traffic-policy.yml
URL
ngrok validates URLs differently depending on their binding. Consult the following documentation for details on valid URLs for HTTP endpoints:Public
HTTP
- The hostname must be a domain with a valid public suffix.
- The port must be
80. If you don’t specify a port, ngrok uses the default80for you.
http://example.ngrok.apphttp://example.ngrok.app:80http://example.partyhttp://example.ngrok.app:81- invalid port: port number must be80, not81http://example.doesnotexist- invalid hostname:.doesnotexistis not a public suffix domainhttp://example.internal- invalid hostname:.internalis not a public suffix domain
HTTPS
- The hostname must be a domain with a valid public suffix.
- The port must be
443. If you don’t specify a port, ngrok uses the default443for you.
Validation
When you create a Cloud Endpoint, you must always specify both a scheme and hostname. To listen for both HTTP and HTTPS traffic, create two endpoints.Domains
When you create a public endpoint, it must match a Domain on your account. Domains help you set up branded domains and manage TLS certificates. You may create wildcard endpoints as well.Bring your own domain
To bring your own domain, first create a Domain record and set up a DNS CNAME record. Then create an endpoint on that domain by specifying a URL with a matching hostname. For example, to create an HTTPS endpoint onhttps://app.example.com, create a Domain and follow the instructions to set up a CNAME record.
Then create a Cloud Endpoint in the dashboard or use the following example to start an endpoint on your domain:
Command line
Wildcard endpoints
You can create a wildcard endpoint which receives traffic for all of the subdomains matching a wildcard pattern like*.example.com.
To create a public wildcard endpoint, you must first reserve a wildcard domain.
For example, if you create the wildcard endpoint https://*.example.com, it receives traffic for https://foo.example.com and https://bar.example.com.
- Connections to URLs which match an online wildcard endpoint are routed to it.
For example, if you have created a wildcard endpoint
https://*.example.com, connections tohttps://foo.bar.baz.example.comroute to it. - Connections are routed to the most specific online endpoint.
For example, if the endpoints
https://*.example.comandhttps://app.example.comare both online, a connection tohttps://app.example.comisn’t routed to the wildcard endpoint.
Command line
For information on how wildcard endpoints are billed, including endpoint hours and Traffic Policy charges when forwarding to internal endpoints, see the wildcard endpoints pricing documentation.
Traffic Policy
Attach Traffic Policy to endpoints to route, authenticate, and transform the traffic through the endpoint.Authentication
Public endpoints are accessible to the public internet unless you secure them with authentication. That’s desirable if you’re hosting a public website, but most often you want to add authentication. You can secure your endpoints with Traffic Policy with any of the following actions:- Basic Auth
- OAuth
- IP Restriction
- Webhook Verification
- JWT
- Mutual TLS
- OpenID Connect
- SAML (early access)
Basic auth example
The following example adds a username and password with the Basic Auth Traffic Policy action.Google OAuth example
The following example enforces a browser-based OAuth redirect flow in front of your endpoint using Google as the identity provider by using the OAuth Traffic Policy action.provider value with any of the Supported Providers that have a managed app available.
Rewriting the host header
Some application servers expect the host header to match a specific value when they receive requests and some use the host header to determine which of many sites to display.
ngrok can rewrite the host header of incoming requests so that your application behaves correctly.
When you rewrite the host header, ngrok also rewrites the location header of HTTP responses automatically to match the hostname of your Endpoint URL.
The following example rewrites the host header to the value localhost using the add-headers Traffic Policy action.
Adding the Host header is a special case that replaces the existing Host header instead of appending a second value.
Traffic observability
Traffic Inspector
Traffic Inspector gives you a real-time view in the ngrok dashboard of the HTTP traffic flowing through your HTTP/S endpoints. You can choose whether Traffic Inspector captures only request metadata or full request and response bodies.Log export logs
You can export logs of traffic to HTTP/S endpoints with ngrok’s events system. ngrok publishes the following events for log exporting:Advanced
HTTP/S endpoints are standards-compliant HTTP reverse proxies.Versions
- HTTP/S endpoints support HTTP/1.1.
- HTTPS endpoints support HTTP/1.1 and HTTP/2.
- HTTP/1.0, HTTP/3, and QUIC are not supported.
HTTP/2
HTTPS endpoints automatically use HTTP/2 for all connections if the client supports it. Client support is determined via standard ALPN negotiation. HTTP/2 is used between the client and your endpoint even if your upstream service doesn’t support HTTP/2. To configure the use of HTTP/2 when sending traffic to an upstream service, consider using an Agent Endpoint.WebSockets
WebSocket connections are supported out-of-the-box. No configuration is required.Hop by hop headers
ngrok doesn’t forward any hop-by-hop headers to the upstream service. As an exception, ngrok forwardsConnection: upgrade headers to support WebSockets.
For information on headers added automatically by ngrok, see Upstream Headers.
Persistent connections
When a connection is made to HTTP/S ngrok endpoints with HTTP/1.1, ngrok may choose to use persistent connections (such as HTTP keep-alive) to improve the performance of future requests from the same client if the client supports it. This behavior isn’t guaranteed and it isn’t configurable. See RFC 7230 for additional details.Well known URIs
/.well-known/acme-challenge
ngrok takes over handling of this path of any HTTP endpoint matching a Domain with automated certificate management enabled.
You may disable this behavior by uploading your own certificate on the matching Domain.
TLS
ngrok automatically handles TLS (SSL) certificate management and termination for you. There is nothing to set up, configure, or manage. TLS connections tohttps endpoints are terminated at ngrok’s cloud service.
If you wish to terminate TLS traffic at the ngrok cloud service or in your upstream application, use a TLS Endpoint instead.
Consult the following documentation for additional details on how ngrok handles TLS termination and certificate management:
Upstream headers
ngrok adds headers to each HTTP request with information about the original client IP, request scheme, and requesthost header value.
Because ngrok appends values to
x-forwarded-for and x-forwarded-proto, be sure to use the last value of the header in your application code to read the values injected by ngrok.
You may remove these headers with the Remove Headers Traffic Policy action.
Limits & timeouts
Contact Support if you need to configure limits and timeouts on connections to HTTP endpoints.Connection
TLS
HTTP
HTTP request
HTTP response
Errors
If ngrok fails to handle an HTTP request, it sets thengrok-error-code header in the HTTP response with a unique ngrok Error Code describing the failure.
ngrok guarantees that the upstream service may never set the ngrok-error-code HTTP response header so you know reliably that it was set by ngrok.
ngrok may return an error under the following conditions:
- Your upstream service timed out or rejected the connection.
- Your upstream service returned a response that wasn’t valid HTTP.
- A Traffic Policy action rejected the request.
- Traffic Policy execution encountered a runtime error.
- ngrok encountered an internal error.