Skip to content
Fixedmark

Inbound · 12 min read

Updated

SNI Routing: Many TLS Hostnames on One IP

SNI routing reads the host name a TLS client sends in clear text in its ClientHello, picks a backend for that name, and relays the still-encrypted connection to it. That lets many hostnames share one IP and port 443 without the router holding any certificate. It fails when no name is sent, for non-TLS protocols, and when Encrypted Client Hello hides the real name.

On this page

How one IP serves many TLS hostnames

Plain HTTP solved name-based hosting long ago. The client sends a Host header, and one server on one IP picks the site. TLS had a gap. The server has to present a certificate before the client sends any HTTP, so it has no Host header to look at. Early HTTPS needed one IP address per certificate for that reason.

Server Name Indication closed the gap. RFC 6066 defines a server_name extension that the client puts in its ClientHello, the first message of the handshake. The RFC gives the motivation directly. It is for servers that host multiple virtual servers at a single network address. The ClientHello travels before any session keys exist, so the name is readable by anything on the path.

An SNI router uses that fact. It never completes a handshake itself. It accepts a TCP connection, reads the first bytes, parses the ClientHello, looks up the name, and opens a connection to the backend for it. Then it sends the ClientHello on unchanged and copies bytes in both directions. The handshake runs between the client and the backend, so the backend holds the certificate and the private key.

  1. The client resolves api.example.com and gets the router's IP.
  2. It opens TCP to that IP on port 443 and sends a ClientHello with server_name set to api.example.com.
  3. The router buffers until the whole ClientHello has arrived. It can span more than one TCP segment.
  4. The router matches the name against its table and connects to that backend.
  5. It replays the buffered bytes to the backend and splices the two connections together until either side closes.

This is the same passthrough idea a forward proxy uses for outbound traffic, turned around. TLS passthrough vs termination covers what a passthrough hop can and cannot see.

What the router reads, and the rules for the name

The server_name extension holds a list of names with a type. Only one type exists, host_name. RFC 6066 sets four rules that matter for routing.

  • The name is ASCII with no trailing dot. Internationalized names travel as A-labels, the xn-- form.
  • DNS names are case-insensitive, so match API.Example.com the same as api.example.com.
  • The list must not hold more than one name of the same type. A client sends one host name.
  • Literal IPv4 and IPv6 addresses are not permitted. A client that connects to https://203.0.113.10/ sends no SNI at all.

The RFC also says what a TLS server does with a name it does not recognise. It either aborts with a fatal unrecognized_name alert or continues the handshake. A router makes the same choice in its own way. It can close the connection, or send it to a default backend that serves a catch-all certificate.

You can watch the name cross the wire. This capture prints the SNI from every ClientHello on port 443 of the machine, while the bytes after the handshake stay unreadable.

Terminal
sudo tshark -i any -f "tcp port 443" \
  -Y "tls.handshake.type == 1" \
  -T fields -e ip.dst -e tls.handshake.extensions_server_name

The ALPN list (h2, http/1.1) and the offered TLS versions are readable too. nginx can route on either. Its docs even show SSH and HTTPS sharing port 443, split by whether the first bytes are TLS at all.

SNI routing with nginx and HAProxy

Both servers do this at the TCP layer, with no certificate configured. nginx uses the ssl_preread module, added in 1.11.5, which exposes the name as $ssl_preread_server_name. It is not built by default from source, though the official Docker image includes it. HAProxy uses the `req.ssl_sni` fetch in a TCP frontend. Its manual says to wait for a complete ClientHello before switching, which is what inspect-delay and req.ssl_hello_type 1 do.

events {}

stream {
    # Pick a backend from the SNI. Nothing is decrypted here.
    map $ssl_preread_server_name $backend {
        api.example.com                  10.0.0.11:443;
        app.example.com                  10.0.0.12:443;
        ~*^[a-z0-9-]+\.tenants\.example\.com$  10.0.0.20:443;
        default                          10.0.0.99:443;
    }

    server {
        listen      443;
        ssl_preread on;
        proxy_pass  $backend;
    }
}

Both configs pass nginx -t and haproxy -c (the nginx:alpine and haproxy:3.2-alpine images). Pointed at four local TLS servers with different certificates, each one sent api.example.com, APP.example.com, and acme.tenants.example.com to the right place, and an unknown name or a missing SNI to the fallback. Two details differ. The nginx regex matches exactly one label under tenants.example.com, while HAProxy's -m end also matches deeper names such as a.b.tenants.example.com. And nginx string keys in a map match without regard to case, while a ~ regex is case-sensitive, which is why the pattern uses ~*.

Test a router without touching DNS

You can send any SNI to any IP from the command line. That tests a route before its DNS record exists, and shows what happens to an unknown name.

Terminal
IP=203.0.113.10

# Which certificate does each name reach?
for name in api.example.com app.example.com unknown.example.org; do
  printf "%s -> " "$name"
  openssl s_client -connect $IP:443 -servername "$name" </dev/null 2>/dev/null \
    | openssl x509 -noout -subject
done

# No SNI at all, as a client dialling the bare IP would send.
openssl s_client -connect $IP:443 -noservername </dev/null

# A full HTTPS request, with curl dialling the IP but sending the name.
curl -v --connect-to api.example.com:443:$IP:443 https://api.example.com/

Passthrough routing compared with a TLS-terminating proxy

A reverse proxy that terminates TLS also reads the SNI, but only to pick which certificate to present. After that it has the plaintext and routes on the Host header, the path, or anything else. Passthrough SNI routing gives up that flexibility in exchange for never holding a key.

An SNI passthrough router compared with a TLS-terminating reverse proxy
QuestionSNI passthroughTLS termination
Who holds the certificate and keyEach backendThe proxy
Route by path or headerNoYes
Add X-Forwarded-ForNo. It cannot touch the HTTP. Use the PROXY protocol insteadYes
Client certificates (mTLS)Reach the backend unchangedEnd at the proxy
Works for non-HTTP TLS (IMAPS, MQTT over TLS)Yes, any implicit TLSOnly if the proxy speaks the protocol
Breach of the proxy exposesConnection metadataEvery request and response

The client address deserves a word. The backend sees a connection from the router, not from the client. A passthrough router cannot add a header, because it cannot write into the encrypted stream. The PROXY protocol solves this by sending one short line, such as PROXY TCP4 192.168.0.1 192.168.0.11 56324 443, before the TLS bytes. The spec says the receiver must be configured to expect it and should accept it only from trusted proxies. A backend that is not configured for it reads that line as a broken ClientHello and fails the handshake. In nginx, proxy_protocol on; in the stream server sends it. In HAProxy, send-proxy-v2 on the server line does.

Where SNI routing breaks

No name to read

A client that dials an IP literal sends no SNI, per RFC 6066. So does any client with SNI turned off. The router must close those connections or send them to a default backend. Tell partners to call the hostname, never the IP, and test with -noservername to confirm the behaviour you chose.

Protocols that are not TLS from the first byte

SNI routing needs implicit TLS, where the ClientHello is the first thing on the wire. HAProxy's manual says req.ssl_sni works for HTTPS on 443, IMAPS on 993, and SMTPS on 465, and not for explicit TLS such as SMTP on 25 or 587 or IMAP on 143. Those start in plain text and upgrade with STARTTLS. Plain HTTP, SSH, and most database protocols have no ClientHello at all. They need a TCP route on a port of their own.

Postgres is a useful special case. libpq sends SNI by default (sslsni=1), but by default it first sends Postgres's own SSL request message, so a generic router finds no ClientHello. The libpq docs say SNI routing then requires sslnegotiation=direct, introduced in PostgreSQL 17 and allowed only with sslmode=require or stricter. The server has to be 17 or later too.

Terminal
psql "host=db.example.com dbname=app user=app sslmode=verify-full sslnegotiation=direct"

HTTP/2 connection reuse across names

RFC 9113 section 9.1.1 lets a client reuse one HTTP/2 connection for another hostname when the certificate covers that name too. The RFC names the risk itself. A middlebox that picks the origin by SNI can then receive requests meant for a different origin. Suppose api.example.com and app.example.com share a wildcard certificate and the router's IP. A browser connected to api may send app requests down the same connection, and the router already sent that connection to the api backend.

There are two fixes. Give each backend a certificate that covers only its own names, so the client never considers reuse. Or make each backend answer 421 Misdirected Request for a Host it does not serve. RFC 9110 says a client that receives 421 may retry over a fresh connection, even for a non-idempotent request. HAProxy's manual warns the same way. SNI only selects a certificate, and later requests may carry other Host values the certificate covers.

HTTP/3 runs over UDP

HTTP/3 uses QUIC over UDP, so a TCP router never sees it. QUIC Initial packets are protected with keys derived from a value in the packet itself, and RFC 9001 says they are not considered to have confidentiality. A QUIC-aware router can read the SNI, but that is a separate code path. If you route only TCP, do not advertise h3 for names behind the router, so clients stay on TCP.

Encrypted Client Hello and SNI routers

RFC 9849, published in March 2026, standardises Encrypted Client Hello. The client encrypts its real ClientHello, the inner one, including the SNI and ALPN, under a public key the server published. It sends that inside an outer ClientHello whose SNI is a public_name belonging to the provider. Clients find the key in DNS, in SVCB or HTTPS records, as RFC 9848 describes.

A router without the ECH key sees only the public name. Every ECH connection looks like a connection to the same host, so name-based routing has nothing to work with. That is the point of ECH for privacy, and it is the limit for routing.

The RFC has an answer built in. In split mode, a client-facing server holds the ECH private key, decrypts the inner ClientHello, and forwards it to the right backend server. The backend completes the handshake. The RFC says the client-facing server forwards all other TLS messages between the client and backend unmodified, and has no access to the plaintext beyond the unencrypted parts of the handshake. In other words, a split-mode client-facing server is an SNI router that can also read the encrypted name. Check that your router supports split mode before you publish ECH keys for names behind it.

  • If you do not publish an ECH configuration for a name, clients have no key and send its real SNI. They may add a GREASE ECH extension, a dummy that the RFC says servers treat as normal. The outer SNI is still the real name, so routing works.
  • A partner's server-side HTTP client sends ECH only if its TLS library supports ECH and it looks up the HTTPS record.

A forward proxy is different. It learns the destination from the CONNECT line, so ECH hides nothing from it. See HTTP CONNECT explained.

How custom domains reach the right backend

Custom domains on a shared platform are SNI routing plus DNS plus a table. A customer wants partners.customer.com to reach their service on your platform. The pieces line up like this.

  1. 1
    The customer points the name at youAn A record to your router's IP, or a CNAME to a name you control that resolves to it. Remove any other A or AAAA records for the name, or some lookups land elsewhere.
  2. 2
    You add the name to the routing tableThe table maps the exact name, or a wildcard such as *.customer.com, to one backend. A name must map to one place on each IP, so the router never has to guess.
  3. 3
    Someone holds a certificate for the nameWith passthrough, that is the backend. It needs a certificate for partners.customer.com that clients trust. With termination, the platform holds it, which is the trade covered in the table above.
  4. 4
    Unknown names fail closedA ClientHello for a name nobody claimed should be closed, not sent to whichever backend is first in the list.

On a router shared between customers, the table is a security boundary. If anyone can add any name, one customer can claim another's domain and receive its traffic. A platform should check ownership before a name goes live, for example with a TXT record only the domain's owner can create, and reserve its own domains outright. Dedicated IPs sidestep part of this, because a customer's DNS points at an address only that customer uses.

Enterprise partners often allowlist the IP they connect to, not only the name. On shared IPs, that allowlist admits every customer on those addresses. A dedicated inbound IP for enterprise firewalls covers that case, and static IP pairs and failover covers why two addresses beat one.

Doing this with Fixedmark

Fixedmark is in early access. Its inbound side routes by SNI in two places, and no Fixedmark node decrypts a partner's TLS in either.

Tunnels put a service on your own machine behind two shared ingress IPs on two nodes. A node reads only the server name in the partner's ClientHello, or the port for a tcp route, and splices the bytes down a session that fixedmarkd holds open. Each route gets a hostname of the form <name>.<org-slug>.<zone>. The domain for that zone is not chosen yet. Your own domains on shared tunnel routes are planned, not available. An http route terminates TLS in fixedmarkd on your machine, and it answers 421 for any Host other than the route's hostname, which is the coalescing defence described above.

Your own host names work on the dedicated inbound IP add-on. You create a tls route with an SNI pattern on that IP, as the SNI docs show.

Terminal
fm routes create --app APP_ID --kind tls --name partners \
  --dedicated-ip IP_ID --sni partners.example.com \
  --origin origin.example.com:443 \
  --partner 198.51.100.0/24
  • Point the name at the IP with an A record, and remove other A or AAAA records for it.
  • A pattern may start with *. to match one label below a domain. Names under fixedmark.net are refused with route.sni_reserved. A name can have one live SNI route on each IP.
  • Your origin holds the certificate. The node never sees a key or a decrypted byte, so client certificates, ALPN, and TLS versions work as your origin sets them.
  • A ClientHello with no server name, or a name no route matches, is closed without reaching any origin, and the log row reads no_route.
  • Only the partner addresses you list get through. Other sources are dropped before the handshake.
  • The origin sees the connection come from your Fixedmark IP. The partner's address is in the connection log as peer. Fixedmark adds no header and no PROXY protocol line, since it does not change the partner's bytes.

In the planned launch pricing, tunnels come with Pro and up, and the dedicated inbound IP is an add-on at $9 per IP-month, billed by the hour. See pricing for the current plans. For a service behind CGNAT, exposing a local service behind CGNAT explains the connector model. Webhook receivers on private networks covers retries and signatures.

Sources

Checked November 2026. Confirm current details on the vendor's site before you decide. Prices and limits change.

Blog

Frequently asked questions

Does SNI routing decrypt my traffic?

No. The router reads the ClientHello, which is sent before any session keys exist, and copies every later byte unchanged. The handshake completes between the client and the backend, which holds the only key.

Can I route plain HTTP or SSH by SNI?

No. SNI exists only in a TLS ClientHello. Plain HTTP routes by its Host header at a proxy that reads HTTP, and SSH or a raw database connection needs its own port.

What happens when a client connects to the IP address directly?

It sends no SNI, because RFC 6066 does not allow IP literals in the server name. The router then closes the connection or sends it to a default backend, depending on how you set it up.

Will Encrypted Client Hello break my SNI router?

Only for names where you publish an ECH key. Then the router sees the provider's public name instead of the real one. Without a published key, clients send the real SNI and routing works as before.

How does the backend learn the client's IP address?

Through the PROXY protocol, if both the router and the backend support it. The router sends one line with the client's address before the TLS bytes. A passthrough router cannot add an X-Forwarded-For header.

Make it fixed.

Fixedmark is in early access. Join the list to get dedicated static IPs when your region opens.