HTTP/S Endpoints
HTTP/S endpoints enable you to serve web services like REST APIs, web
applications, websites and websocket servers. Serving a web application is as
simple as 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
Agent Endpoint
Agent Endpoints are the easiest way to get started with ngrok. An agent endpoint is started by a Secure Tunnels agent. The endpoint lives for the lifetime of the process and forwards traffic to a port or URL of your choosing.
Create the endpoint https://example.ngrok.app
and forward its traffic to a
local port.
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Loading…
Loading…
Javascript SDK Docs:
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
Loading…
Cloud Endpoint
Cloud endpoints are created via the ngrok Dashboard or API. They are persistent and live until they are deleted. Traffic Policy controls how a cloud endpoint handles traffic.
Create an HTTPS cloud endpoint
which returns a Hello world!
200 OK response.
- Agent CLI
Loading…
Loading…
URL
URLs are validated differently depending on their binding. Consult the following documentation for details on valid URLs for TCP endpoints:
Public
HTTP
- The hostname must be a domain with a valid public suffix.
- The port must be
80
. If you do not specify a port, the default80
will be used for you.
Examples
http://example.ngrok.app
http://example.ngrok.app:80
http://example.party
http://example.ngrok.app:81
- invalid port: port number must be80
, not81
http://example.doesnotexist
- invalid hostname:.doesnotexist
is not a public suffix domainhttp://example.internal
- invalid hostname:.internal
is not a public suffix domain
HTTPS
- The hostname must be a domain with a valid public suffix.
- The port must be
443
. If you do not specify a port, the default443
will be used for you.
Internal
Kubernetes
Valid URLs
Invalid URLs
Validation
When you create an agent endpoint, if you do not specify a complete URL, following defaults are used to construct an endpoint URL. When you create a cloud endpoint, you must always specify both a scheme and hostname.
URL Part | Default |
---|---|
Scheme | https |
Hostname | randomly selected |
Port | 443 if scheme is https 80 if scheme is http |
Consult the following table of examples of URL defaulting:
Value | Endpoint URL |
---|---|
https://example.ngrok.app | https://example.ngrok.app |
http://example.ngrok.app | http://example.ngrok.app |
example.ngrok.app | https://example.ngrok.app |
app.example.com | https://app.example.com |
https://example.internal | https://example.internal |
https://example.internal:1234 | https://example.internal:1234 |
http://example.internal | http://example.internal |
foo.internal | https://foo.internal |
{empty} | https://1eb2-181-80-12-3.ngrok.app (randomly selected) |
If you would like 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 endpoints with wildcard domains as well.
Endpoints with randomly-assigned hostnames are an exception and won't match an existing Domain object.
Bring your own domain
If you want 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 on https://app.example.com
, create
a Domain and follow the instructions to
set up a CNAME record. Then use the following example to start an endpoint on
your domain:
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Loading…
Loading…
Javascript SDK Docs:
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
Loading…
Wildcard endpoints
You can create an endpoint which will receive traffic for all of the subdomains
matching a given wildcard domain like *.example.com
. You must create a
wildcard domain to create a
public wildcard endpoint.
For example, if you create the wildcard endpoint https://*.example.com
, it
will receive traffic for https://foo.example.com
and
https://bar.example.com
.
- Connections to URLs which match an online wildcard endpoint will be routed to
it. For example, if you have created a wildcard endpoint
https://*.example.com
, connections tohttps://foo.bar.baz.example.com
will route to it. - Connections are routed to the most specific online endpoint. For example, if
the endpoints
https://*.example.com
andhttps://app.example.com
are both online, a connection tohttps://app.example.com
will not be routed to the wildcard endpoint.
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Loading…
Loading…
Javascript SDK Docs:
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
Loading…
Randomly assigned hostnames
If you run create a public endpoint without specifying a hostname, ngrok will
automatically assign a random one for you.by selecting a random subdomain of one of our ngrok-managed
Domains to your endpoint.
For example, the command ngrok http 80
may create an endpoint like
https://1eb2-181-80-12-3.ngrok.app
.
The following example create an HTTPS endpoint on a randomly assigned hostname that forwards to port 8080.
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Loading…
Loading…
Javascript SDK Docs:
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
Loading…
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 Example
Adds a username and password with the Basic Auth Traffic Policy action.
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Loading…
Javascript SDK Docs:
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
Loading…
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.
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Loading…
Javascript SDK Docs:
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
Loading…
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.
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Loading…
Javascript SDK Docs:
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
Loading…
Agent Forwarding
The ngrok agent and Agent SDKs forward traffic that your endpoints receive to upstream services. You specify a URL or port number to instruct the ngrok agent where and how to forward traffic.
HTTPS forwarding
The scheme in your upstream URL is used to determine whether to forward HTTP or
HTTPS traffic to the upstream service. If you do not specify a scheme, the
default http
scheme is chosen unless you forward to port 443
, in which
case ngrok will use https
. Consult the following table of examples.
Upstream URL | Normalized Value |
---|---|
http://localhost:1234 | http://localhost:1234 |
https://localhost:1234 | https://localhost:1234 |
localhost:1234 | http://localhost:1234 |
1234 | http://localhost:1234 |
localhost:443 | https://localhost:443 |
443 | https://localhost:443 |
ngrok assumes that the network you run the agent on is private and it does not
verify the TLS certificate presented by the upstream service. You may change
this behavior with the flags --upstream-tls-verify
and
upstream-tls-verify-cas
.
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Forwarding to an upstream HTTPS service is not supported via SSH.
Loading…
For HTTP/2 Use: config.HTTPEndpoint(config.WithAppProtocol("http2"))
Go Package Docs:
Loading…
Javascript SDK Docs:
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
Add the k8s.ngrok.com/app-protocols
label to the Service definition
targeted by your ingress backend to instruct the Operator to use
https
when forwarding connections.
Loading…
Non-local forwarding
Agents don't just forward to ports on your localhost. You can forward traffic
to any address or URL reachable from the agent. For example, if you want to
forward traffic to a HTTP server running on your network at 192.168.1.2:80
:
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Loading…
Loading…
Javascript SDK Docs:
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
The ngrok Kubernetes Operator always forwards its traffic. All of our other
examples show the most common forwarding case: a Service
object that defines
a label selector of matching pods to forward traffic to.
But you can also forward to an explicit set of IP
addresses
on the same network using Service
and EndpointSlice
objects.
Loading…
HTTP/2 forwarding
When agents forward to upstream http/2 services, connections use HTTP/1.1 by default.
You can configure the agent, SDKs and Kubernetes Operator to instead use HTTP/2 when forwarding to your upstream service.
Forwarder | Option | Docs |
---|---|---|
Agent | --upstream-protocol | Agent CLI flags |
Agent SDKs | language-dependent | Agent SDKs |
Kubernetes Operator | appProtocol on the Tunnel CRD | Kubernetes Operator |
When http2 forwarding is enabled, all requests to your upstream service will be transmitted over HTTP/2 Cleartext since TLS was already terminated at the ngrok cloud service. We cannot use TLS-ALPN at this time. We rely on HTTP/2 with Prior Knowledge currently.
Serving file directories
The ngrok agent supports the file://
scheme in a forwarding URL. When you use
the file://
scheme, the ngrok agent serves local file system directories by
using its own built-in file server, no separate server needed. It works just
like python3 -m http.server
but it is built directly into the ngrok agent.
Paths in file://
URLs must be specified as absolute paths.
Serve files in /var/log
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Serving directory files is not supported via SSH.
Loading…
Serving directory files is not supported in the Javascript SDK.
Serving directory files is not supported in the Python SDK.
Serving directory files is not supported in the Rust SDK.
Serving directory files is not supported in the ngrok Kubernetes Operator.