> ## Documentation Index
> Fetch the complete documentation index at: https://ngrok.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# TLS Cloud Endpoints

> Learn how to create and configure TLS endpoints with ngrok for handling encrypted TLS traffic using SNI-based routing.

TLS endpoints enable you to deliver any network service that runs over a TLS-based protocol.
TLS endpoints make no assumptions about the wrapped protocol being transported.

TLS endpoints inspect the [Server Name Indication (SNI)](#sni)
data on incoming TLS connections to route connections to the appropriate
endpoint.

Because the TLS protocol describes no application-level semantics, ngrok can
only offer a [limited set of Traffic Policy actions](https://ngrok.com/docs/gateway/traffic-policy/actions.md)
to handle TLS traffic.

If you are delivering an HTTPS application, prefer to create an [HTTP
Endpoint](https://ngrok.com/docs/gateway/endpoints/http.md).

## Quickstart

[Cloud endpoints](https://ngrok.com/docs/gateway/endpoints/cloud-endpoints.md) are persistent and live until they are
deleted.
They are created via [the
ngrok dashboard](https://dashboard.ngrok.com/endpoints/new) or [API](https://ngrok.com/docs/api.md). [Traffic Policy](https://ngrok.com/docs/gateway/traffic-policy.md) controls how a Cloud Endpoint
handles traffic.

See the [Cloud Endpoints Quickstart](https://ngrok.com/docs/getting-started/cloud-endpoints-quickstart.md) 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 a `Hello world!` 200 OK response.

```bash title="Command line" theme={null}
ngrok api endpoints create \
	--url tls://{your-domain-here}.ngrok-free.dev \
	--traffic-policy "$(<traffic-policy.yml)"
```

```yaml title="traffic-policy.yml" mode=traffic-policy theme={null}
on_http_request:
- actions:
  - type: custom-response
    config:
      status_code: 200
      headers:
        content-type: text/plain
      body: "Hello world!"
```

## URLs

ngrok validates URLs differently depending on their [binding](https://ngrok.com/docs/gateway/endpoints/bindings.md).
Consult the following documentation for details on valid URLs for TLS endpoints:

* [Public Endpoint URLs](https://ngrok.com/docs/gateway/endpoints/public-endpoints.md#https-tls)
* [Internal Endpoint URLs](https://ngrok.com/docs/gateway/endpoints/internal-endpoints.md#urls)
* [Kubernetes Endpoint URLs](https://ngrok.com/docs/gateway/endpoints/kubernetes-endpoints.md#urls)

There is no standard scheme for TLS URLs, so ngrok renders them as `tls://`.

## Bindings

TLS endpoints support `public` and `internal` bindings.
They don't support the `kubernetes` binding.

## Traffic Policy

Attach [Traffic Policy](https://ngrok.com/docs/gateway/traffic-policy.md) to endpoints to route, authenticate, and transform the traffic through your TLS endpoints.

### Authentication

When you create public TLS endpoints, you often want to secure them with authentication.
You can secure your TLS endpoints with the following [Traffic Policy](https://ngrok.com/docs/gateway/traffic-policy.md) actions.
There is a limited set of actions available to authenticate TLS traffic because the TLS protocol is low-level.

* [IP Restriction](https://ngrok.com/docs/gateway/traffic-policy/actions/restrict-ips.md)
* [Mutual TLS](https://ngrok.com/docs/gateway/traffic-policy/actions/terminate-tls.md)

## TLS termination

TLS Endpoints give you the flexibility to define where TLS termination occurs.
You can configure your endpoint to terminate TLS at the ngrok cloud service, or you can achieve [end-to-end encryption](https://ngrok.com/docs/gateway/domains/tls-termination.md#end-to-end-encryption) by terminating at the agent or your upstream service.
When you use end-to-end encryption, the ngrok cloud service can't see payloads that transit through your endpoints.

Consult the documentation on [TLS Termination Locations](https://ngrok.com/docs/gateway/domains/tls-termination.md#termination-location) for additional details.

### Example

To terminate TLS Cloud Endpoint traffic at an agent or an upstream service, you must create a Cloud Endpoint, then use the [`forward-internal`](https://ngrok.com/docs/gateway/traffic-policy/actions/forward-internal/) action to forward traffic to an internal endpoint.

#### 1. Create a TLS Cloud Endpoint

Create a TLS Cloud Endpoint [in the dashboard](https://dashboard.ngrok.com/endpoints/new), or with the following CLI command, adding your Traffic Policy file:

```bash title="Command line" theme={null}
ngrok api endpoints create \
	--url tls://{your-domain-here}.com \
	--traffic-policy "$(<traffic-policy.yml)"
```

#### 2. Create a Traffic Policy file

Create a Traffic Policy file to forward traffic to the internal endpoint, adding `.internal` to your domain for the URL.
For example, if you're using `example.ngrok.dev`, your internal endpoint URL should be `tls://example.internal`:

```yaml title="traffic-policy.yml" mode=traffic-policy theme={null}
on_tcp_connect:
  - actions:
      - type: forward-internal
        config:
          url: tls://{your-domain-here}.internal:{your-port-here}
```

#### 3. Create an internal endpoint

Create an internal endpoint using the same URL that your Traffic Policy references.

> [tab] At the upstream
>
> ```bash theme={null}
> ngrok tls {your-port-here} \
> --url tls://{your-domain-here}.internal \
> --binding internal
> ```

> [tab] At the Agent
>
> ```bash theme={null}
> ngrok tls 80 \
> --binding internal \
> --url example.internal \
> --crt /path/to/app-example-com-crt.pem \
> --key /path/to/app-example-com-key.pem
> ```

To learn more about terminating TLS at the agent, see the [Agent Endpoint TLS documentation](https://ngrok.com/docs/gateway/endpoints/tls.md#termination).

### Certificates

It's very common to encounter certificate errors when working with TLS endpoints.
When terminating TLS at ngrok's cloud service, ngrok automatically selects, provisions, and manages certs for you.
When performing [end-to-end encryption](https://ngrok.com/docs/gateway/domains/tls-termination.md#end-to-end-encryption) by terminating at the upstream service, you become responsible for provisioning, managing, and distributing certificates.

Consult the documentation on [TLS Certificates](https://ngrok.com/docs/gateway/domains/tls-certificates.md) for details about certificate selection, provisioning, and management.

## Compatible clients

### SNI

TLS endpoints only work with modern TLS clients that populate the SNI extension.
See the documentation on [TLS Termination](https://ngrok.com/docs/gateway/domains/tls-termination.md#sni) for additional details on compatible clients.

### STARTTLS

ngrok doesn't support protocols that begin in plain text and upgrade to TLS through a mechanism like STARTTLS in SMTP or IMAP.
If you need to support connections that upgrade to TLS, use a [TCP Endpoint](https://ngrok.com/docs/gateway/endpoints/tcp.md).

## Observability

### Traffic Inspector

The [TCP tab in Traffic Inspector](https://ngrok.com/docs/obs/traffic-inspection/tcp-connections.md) lists each connection to your TLS endpoint after it closes, including client IP, TLS handshake details, bytes transferred, and any ngrok error.

### Log exports

You can export logs of traffic to TLS endpoints with [ngrok's events system](https://ngrok.com/docs/obs.md).
ngrok publishes the following events for log exporting:

| Log | When |
| - | - |
| [tcp\_connection\_closed.v0](https://ngrok.com/docs/obs/events/reference.md#tcp-connection-closed) | Published when a TCP connection to a TCP endpoint completes. |

## Limits & timeouts

[Contact Support](mailto:support@ngrok.com) if you need to configure limits and timeouts on connections to TLS endpoints.

### Connections

| Limit | Name | Notes |
| - | - | - |
| 3 seconds | ClientHello Timeout | Time between connection establishment and ClientHello received |
| 5 minutes | Client Idle Timeout | Time since data was last transmitted by the upstream service |
| 5 minutes | Server Idle Timeout | Time since data was last transmitted by the upstream service |
| No limit | Data transmitted | Data transmitted by the client or upstream service |

### TLS

## Errors

If a TLS handshake fails, ngrok sends an appropriate TLS abort code to the client.

In all other cases, if ngrok encounters an error while handling TLS connections to your endpoints (for example, no available backends or an internal server error), it closes the connection.
The TLS protocol and its implementations aren't flexible enough to deliver additional rich error information when failures occur.

Use the [observability](#observability) features to understand connection handling errors.

## API

You can create TLS Endpoints programmatically.
Consult the documentation on [Endpoint APIs](https://ngrok.com/docs/api-reference/endpoints/list.md).

## TLS Cloud Endpoint pricing

TLS endpoints are available on Hobbyist and Pay-as-you-go plans.
Consult the [pricing](https://ngrok.com/docs/pricing-limits.md#endpoint-limits) documentation for billing details.

See [Domains pricing](https://ngrok.com/docs/gateway/domains.md#pricing) for details on pricing for custom domains, wildcard endpoints, and more.

Zero-knowledge TLS is available on the Pay-as-you-go plan.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.