Proxying protocols: SSE, WebSocket, gRPC, HLS, MQTT, PostgreSQL and more
Conduit has two ways to carry a protocol, and the first question for any protocol is which one it needs.
| Mode | What Conduit does | Pick it when | Configured as |
|---|---|---|---|
| HTTP | Parses the request, runs the filter chain (IP filter, rate limit, auth, scripts…), routes by host and path, load-balances, retries, caches. | The protocol is carried by HTTP: SSE, WebSocket, gRPC, GraphQL, HLS, WebRTC signalling. | proxy: or static: on a site |
| TCP | Relays bytes in both directions. Never looks inside; none of the HTTP features apply. Needs --features tcp. |
Anything else on a TCP port: databases, brokers, mail, FTP, SSH, RTMP. | tcp: on a site, one port per site |
| Protocol | Mode | What you set | Tested by |
|---|---|---|---|
| SSE | HTTP | timeout.readMs for silent streams |
scripts/e2e/streaming.sh |
| WebSocket | HTTP | websocket: true, timeout.readMs |
scripts/e2e/streaming.sh |
| gRPC | HTTP | HTTP/2 on both sides, http2: "h2c" for a plaintext upstream |
scripts/e2e/grpc.sh |
| GraphQL | HTTP | nothing special; subscriptions use WebSocket or SSE | covered by the WebSocket and SSE checks |
| WebDAV | HTTP | limits.maxBodyBytes for uploads; keep the upstream at the same path |
scripts/e2e/webdav.sh |
| HLS / DASH | HTTP (static: or proxy:) |
staticOptions.maxAge |
by hand (see below) |
| WebRTC | HTTP for signalling; media is UDP and cannot be proxied | — | signalling is WebSocket |
| RTMP | TCP | one site on port 1935 | scripts/e2e/protocols.sh |
| MQTT | TCP (or WebSocket) | one site on 1883 / 8883 | scripts/e2e/protocols.sh |
| PostgreSQL | TCP | one site on 5432 | scripts/e2e/protocols.sh |
| Redis | TCP | one site on 6379 | scripts/e2e/protocols.sh |
| SMTP | TCP | one site on 25 / 587 | scripts/e2e/protocols.sh |
| FTP | TCP | the control port and every passive data port | scripts/e2e/protocols.sh |
| SFTP / SSH | TCP | one site on 22 | scripts/e2e/protocols.sh |
The e2e scenarios run Conduit in a Docker network against small servers (for the wire protocols, servers that answer the
opening exchange of the real protocol, not a full database). scripts/e2e/run.sh runs them.
What a TCP site does and does not do
sites:
- port: 5432
tcp:
targets: ["db-primary.internal:5432"]
connectTimeoutMs: 5000
Several targets (strategy: round-robin or random) are for interchangeable backends, such as a pool of read replicas on
a site of their own. Do not list a primary and a replica together: Conduit does not know their roles.
- It relays bytes both ways and passes a half-close on, so a client that finishes sending and waits for the answer works.
- By default it does not terminate TLS. A TLS client talks to the upstream through Conduit and verifies the
upstream’s certificate (checked in
protocols.shwithopenssl s_server). That is also howSTARTTLS-style upgrades and PostgreSQL’sSSLRequestpass through. With atlsblock on the site (certandkey, optionallyclientAuth) Conduit terminates TLS instead: the client verifies Conduit’s certificate and the upstream gets the decrypted bytes (see TLS on a TCP site). - It adds nothing to the stream: the upstream sees Conduit’s address as the client, unless
tcp.sendProxyProtocolwrites a PROXY protocol header first. Anything that decides by client address on the backend (pg_hba.conf, mail relay rules, fail2ban) sees Conduit otherwise, and the upstream must be set up to expect the header when it is sent. In the other direction,proxyProtocolon the site reads the header of a load balancer in front of Conduit. - None of the HTTP features apply: no IP filter, rate limit, authentication or metrics per route. Conduit refuses a
configuration that puts
ipFilter,rateLimit,basicAuth,apiKey,jwtAuth,forwardAuth,consumers,limitsormiddlewareon atcpsite (it would be silently ignored and look like protection). Put access control in front of the port (a firewall or network policy) or on the backend. - Limits:
maxConnectionscaps the connections open on the site andmaxConnectionsPerIpthe connections from one client address (IPv6 clients are counted per /64, an IPv4-mapped address as the IPv4 address); a connection over a cap is closed at once, before any upstream is tried. Neither is set by default (the operating system’s limit on open files still applies). A connection that has been quiet in both directions foridleTimeoutSecsis closed: 3600 (one hour) by default,0for never. A long-lived idle connection (an SSH session left open, a database pool) needs a larger value or0. - No UDP. Port ranges are not supported: one
sitesentry is one port. - Several upstreams are load-balanced per connection, not per message, and a target that fails to connect is passed over for a few seconds (see TCP Proxy). A connection that is already relayed is never moved. For a database that means Conduit balances connections, not queries; it knows nothing of primary or replica roles.
TLS on a TCP site
sites:
- port: 993
tls:
cert: /etc/conduit/mail.crt
key: /etc/conduit/mail.key
clientAuth: { ca: /etc/conduit/clients-ca.pem } # optional: only clients with a certificate of this CA
tcp:
targets: ["dovecot.internal:143"] # the upstream speaks plaintext
- The handshake happens in Conduit, so a client that does not speak TLS is closed and the upstream never sees its bytes.
The upstream receives the decrypted stream, which suits mail, MQTT, Redis and the like on a port that is TLS-only for
clients. Caps,
idleTimeoutSecsandsendProxyProtocolwork as on a plain site. clientAuth(mutual TLS) is checked in the handshake: a client without a certificate of that CA never reaches the upstream.optional: trueasks for a certificate but does not require one; Conduit does not pass the certificate on.proxyProtocolon such a site reads the load balancer’s header before the handshake (the header is outside the TLS stream); the client address it carries is the onemaxConnectionsPerIpcounts andsendProxyProtocolpasses on.- Not supported on a TCP site:
tls.acme(its HTTP-01 challenge needs a plain HTTP port; usecertandkey),tls.httpRedirectPort,tls.versionsandtls.ciphers(refused everywhere, #189), one certificate per SNI name, and TLS to the upstream (the upstream connection is plain). The site needs an explicitport. A changedtlsblock needs a restart. maxConnectionsandmaxConnectionsPerIpcount a connection after its handshake completes: a client that connects and never finishes the handshake is not counted, as on an HTTPS port. Keep the port behind a firewall or the load balancer.- Terminating TLS drops the TLS end-of-stream protection towards the upstream: a client that closes without
close_notifylooks to a plaintext upstream like a normal close (Conduit logs it at debug level only). Do not put a protocol on such a port that treats a closed connection as a complete message.
Shown by tests/tcp_tls.rs (real TLS client: decrypted relay, plaintext refused, client certificates, header then handshake)
and scripts/e2e/tcp-tls.sh (Python TLS client and a plaintext echo upstream in the Docker network).
Server-Sent Events (SSE)
An event stream is a long HTTP response. No special setting is needed; the route is an ordinary proxy route:
sites:
- port: 443
host: app.example.com
tls: {cert: ./cert.pem, key: ./key.pem}
proxy:
"/events":
targets: ["http://events.internal:9000"]
timeout: {readMs: 120000} # see the note on silence below
What the e2e test shows, over plain HTTP, TLS and HTTP/2:
- Events reach the client as the upstream sends them (three events 0.5 s apart arrive 0.5 s apart; the first within
0.4 s), and the
text/event-streamtype is kept. Conduit does not compress proxied responses, so nothing holds events back. Last-Event-IDandAccept: text/event-streamreach the upstream, so a reconnectingEventSourceresumes.timeout.readMsis an idle timeout (30 s by default): the stream is closed when the upstream sends nothing for that long. A stream that can stay silent longer thanreadMsmust either send a comment line (: keep-alive) more often, or the route needs a largerreadMs. A silence shorter thanreadMsis fine, a longer one ends the stream (2 s against a 4 s gap, and 10 s against the same gap, are both in the test).
WebSocket
Upgrades are refused with 502 unless the route says websocket: true:
proxy:
"/socket":
targets: ["ws://ws.internal:9001"]
websocket: true
timeout: {readMs: 300000}
ws:// or http:// in targets: both work, and they mean the same upstream. A WebSocket connection starts as an
ordinary HTTP/1.1 request with Upgrade: websocket (RFC 6455 §4.1),
and Conduit is the one that forwards that request, so the target is an address, not a protocol. ws:// is accepted as
http:// (port 80 by default) and wss:// as https:// (port 443, TLS to the upstream). Use wss:// or https:// when
the upstream itself speaks TLS. The route’s websocket: true is what allows the upgrade, not the scheme of the target.
The e2e scenario uses ws:// for its main route and http:// for the others.
Through a plain port and a TLS port (ws:// and wss://) the test passes the handshake, text messages, ping/pong,
fragmented messages, a 1 MiB binary message (hash compared) and the close handshake including the upstream’s close code. The
upstream sees the request path (after stripPrefix), the Origin and X-Forwarded-For.
timeout.readMsis an idle timeout here too: a socket in which nothing travels either way for that long is closed. A ping from either side counts as traffic and keeps it open, so a client that pings every 20–30 s works with the default.Sec-WebSocket-*headers pass to the upstream as sent; check the sub-protocol you need with your own client (not covered by the test).- The upgrade is the HTTP/1.1 one (
Upgrade: websocket). WebSocket over HTTP/2 (RFC 8441) is not covered by the test; use HTTP/1.1 for the socket.
gRPC
gRPC is HTTP/2 with trailers. Both sides of Conduit must speak HTTP/2:
| Hop | Setting |
|---|---|
| Client → Conduit over TLS | tls: and http2: {} on the site (HTTP/2 is negotiated through ALPN) |
| Client → Conduit without TLS | http2: {h2c: true} on the site (prior knowledge, no upgrade) |
| Conduit → upstream over TLS | http2: true on the route (ALPN h2); upstreamTls: {verify: false} for a self-signed upstream (this switches certificate verification off, so the connection can be intercepted: only on a network you trust, otherwise give the upstream a certificate the system trusts); the host still needs a CA bundle, see Upstream TLS verification |
| Conduit → upstream without TLS | http2: h2c on the route |
http2: true is not enough for a plaintext upstream: HTTP/2 is negotiated through ALPN, which does not exist without TLS,
so Conduit would speak HTTP/1.1 to it (the control case in the test shows gRPC failing that way). http2: h2c makes it use
HTTP/2 with prior knowledge (RFC 9113 §3.3), as nginx
grpc_pass grpc://, Envoy and Traefik (h2c://) do. Over TLS h2c behaves like true. One consequence of Pingora’s connection pool: an h2c route and an http2: true route that
point at the same plaintext host:port can share one HTTP/2 connection (requests stay separate streams), so give two routes
that need different behaviour different upstream addresses.
sites:
- port: 443
host: grpc.example.com
http2: {}
tls: {cert: ./cert.pem, key: ./key.pem}
proxy:
"/": {targets: ["http://orders.internal:50051"], http2: h2c}
grpc.sh runs a unary call with trailing metadata, server streaming (messages arrive one by one), client streaming of 1 MB,
an error status with its message and trailers (INVALID_ARGUMENT), and a deadline (DEADLINE_EXCEEDED), through each
combination in the table.
- Route by service with a path prefix: gRPC paths are
/package.Service/Method, so"/orders.Orders/"is a prefix. - The idle
timeout.readMsapplies to streaming calls as well (tested for SSE and WebSocket, the same code path): raise it for calls that can be silent. - Active health probes of a plaintext upstream (
http://,ws://) speak HTTP/1.1, which a plaintext gRPC server does not answer; with ahealthCheckon such a route the upstream is marked unhealthy (observed with the Python gRPC server). UseoutlierDetection(judges real calls) instead. A TLS upstream (https://) is probed by connecting only, so this does not apply to it. - gRPC-Web (HTTP/1.1 from a browser) is plain HTTP and needs no
h2c, but is not part of the test.
GraphQL
Queries and mutations are POST requests with a JSON body: an ordinary proxy route, all HTTP features apply (rate limit
per client, JWT, cache for GET persisted queries). Subscriptions travel over a WebSocket (graphql-transport-ws) or SSE,
so the route that serves them needs websocket: true or the SSE note about readMs.
proxy:
"/graphql": {targets: ["http://api.internal:4000"], websocket: true, timeout: {readMs: 120000}}
WebDAV
WebDAV (RFC 4918) is HTTP with more methods, so it is an ordinary proxy route. Nothing needs enabling: Conduit has no
list of allowed methods, and PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, DELETE, PUT and OPTIONS
reach the upstream as sent.
limits: {maxBodyBytes: 1073741824} # a site setting: the largest upload (1 GiB here)
proxy:
"/files": {targets: ["http://dav.internal:8080"], timeout: {readMs: 600000}}
What webdav.sh shows, against an upstream that echoes every request:
- The methods, the request bodies (PROPFIND and LOCK XML, a 1 MiB
PUTcompared by length and SHA-256) and the headersDepth,Overwrite,Timeout,Lock-Token,If,DestinationandContent-Typearrive unchanged. The statuses (207, 201, 204) and the response headersDAV,AllowandLock-Tokencome back unchanged. The client’sHostis forwarded, so an upstream that compares it with the host inDestination(Apachemod_davdoes) sees the same one. - Conduit does not rewrite URLs that the client wrote.
Destination, the resource tags ofIf, theLocationof a201and the<href>elements of a multistatus body are in the client’s namespace, and are passed on and returned as they are. With the default (nostripPrefix) the upstream is mounted at the same path as the route and all of this is consistent; that is the setup to start with. WithstripPrefix: truethe upstream sees paths without the prefix butDestinationstill has it, and thehrefs it returns do not: either the upstream is told its public prefix (Radicale, for one, takes it from anX-Script-Nameheader, whichrequestTransform.setHeaderscan add; check your server’s documentation, this is not covered by the test), or the route setsrewriteDestination: true(next point). The upstream’s own absolute URLs (aLocation, an<href>that names its internal host) are also passed on as it wrote them, so configure its public origin as well as its path, or a client may be sent to a host it cannot reach. rewriteDestination: true(opt-in, default off) applies the route’sstripPrefixandrewriterules to the paths inDestinationand in the resource tags ofIf(<URL>outside the parentheses, RFC 4918 section 10.4), so that aCOPYorMOVEthrough a stripping route names a resource the upstream knows. Only the path of a URL changes: the scheme, the authority, the query, the state tokens and entity tags inside the parentheses ofIfstay as they were, a URL of another authority than the request’sHost, a path outside the route’s prefix (the prefix must end at a segment boundary:/mvxis not under/mv) and a result that would not be a plain absolute path (/mv//evil.com/xwould become the network-path reference//evil.com/x) are left as the client wrote them, and a request without the headers is untouched. Do not turn it on for an upstream that expects the public path (Radicale withX-Script-Name). The response side is not rewritten: aLocationor<href>that the upstream writes in its own namespace stays as written.webdav.shchecks it on astripPrefixroute and on arewriteroute, next to the default routes that leave both headers alone.- The site’s
limits.maxBodyBytesapplies to uploads, so raise it for largePUTs.timeout.readMsis an idle timeout: a transfer that stalls for that long is closed. - The cache stores only
GETandHEADby default, soPROPFINDis never served from it.
A static site is read-only: a file that exists is served for GET and HEAD, and every other method (PUT, DELETE,
PROPFIND, MKCOL …) is answered 405 Method Not Allowed with Allow: GET, HEAD, OPTIONS, so a WebDAV client that
tries to mount a static: directory is told plainly that it cannot write instead of being sent the file. Conduit does not
serve WebDAV itself; put a WebDAV server behind a proxy: route.
HLS and DASH
HLS is plain HTTP: a playlist (.m3u8) and media segments. Two ways to serve it:
sites:
- port: 8080
static: ./video
staticOptions:
maxAge: 1h # the default is `no-cache`; fine for a live playlist, too cautious for old segments
or proxy an origin or packager with proxy: (add cache: on the route to absorb many viewers; see
Caching). Checked by hand against a static folder: ranged requests answer 206 with a
Content-Range, ETag with If-None-Match answers 304.
Conduit serves .m3u8 as application/vnd.apple.mpegurl, .m3u as audio/mpegurl, .ts as video/mp2t, .m4s as
video/iso.segment and .mpd as application/dash+xml. (Before this guide, .m3u8 went out as audio/x-mpegurl and .ts as
video/vnd.dlna.mpeg-tts, which some players and CDNs reject.)
A live playlist changes every few seconds. Do not give it a long maxAge or cache TTL; keep the segments and the playlist on
separate prefixes if you want to cache one and not the other.
WebRTC
Only the signalling goes through Conduit: it is HTTP or WebSocket (see above). The media is UDP (ICE, DTLS, SRTP), and Conduit has no UDP proxy, so media must reach the peers or the SFU/TURN server directly (open its UDP port range) or through a TURN server. A TURN server that listens on TCP can be reached through a TCP site, which Conduit relays like any TCP port (not tested).
RTMP
RTMP (publish from OBS or ffmpeg, play from a media server) is a TCP stream on port 1935:
sites:
- port: 1935
tcp: {targets: ["media.internal:1935"]}
The test completes the RTMP handshake through the site. A published stream can last for hours; the TCP idle timeout (idleTimeoutSecs, one hour by default) only closes a connection
in which nothing moves in either direction, so a live stream is not cut, and a long pause between publishes needs a larger value. RTMPS is RTMP inside TLS, which passes through untouched. HTTP-FLV and HLS output of the same media server are HTTP.
MQTT
sites:
- port: 1883
tcp: {targets: ["broker.internal:1883"]}
- port: 8883 # MQTT over TLS: passes through, the broker holds the certificate
tcp: {targets: ["broker.internal:8883"]}
The test sends CONNECT, a QoS 1 PUBLISH and PINGREQ and checks the acknowledgements. MQTT over WebSocket is a WebSocket
route (websocket: true), not a TCP site. The broker sees every client as Conduit’s address, so use unique client IDs, not
IP-based ACLs.
PostgreSQL
sites:
- port: 5432
tcp: {targets: ["pg.internal:5432"]}
The test opens a connection through the site with the SSLRequest first, as psql does; the answer comes from the server and
the startup, authentication and a query go through. TLS to PostgreSQL is end to end between client and server; Conduit
does not see it. Without sendProxyProtocol the server sees Conduit’s address in pg_hba.conf and pg_stat_activity.
Balancing is per connection; do not point it at a primary and a replica together.
Redis
sites:
- port: 6379
tcp: {targets: ["redis.internal:6379"]}
PING, SET and a 100 000-byte GET pass through in the test. Redis Cluster and Sentinel tell clients the addresses of the
nodes (MOVED, ASK), so those clients bypass a single proxy address: use Conduit in front of one standalone Redis (or
a managed endpoint), not in front of a cluster’s nodes.
SMTP
sites:
- port: 25
tcp: {targets: ["mail.internal:25"]}
- port: 587
tcp: {targets: ["mail.internal:587"]}
EHLO and a full message transaction pass in the test (Python smtplib). STARTTLS and implicit TLS (465) are between
client and server and pass through; the STARTTLS exchange itself is not part of the test. The mail server sees Conduit’s
address as the client, which matters for relay rules, rate limits, SPF checks and spam scoring on that server.
FTP
FTP uses a control connection (port 21) and a separate data connection for every listing and transfer. In passive
mode the server tells the client where to connect for the data: in the reply to PASV (227) or EPSV (229). Conduit
does not rewrite that reply, so the server has to announce an address and port that reach Conduit, and Conduit needs a
TCP site for every passive port:
sites:
- port: 21
tcp: {targets: ["ftp.internal:21"]}
- port: 30000 # the server's passive range, one site per port
tcp: {targets: ["ftp.internal:30000"]}
- port: 30001
tcp: {targets: ["ftp.internal:30001"]}
On the FTP server set the passive address to the Conduit host and a small passive range (for vsftpd: pasv_address,
pasv_min_port, pasv_max_port). The test does exactly that (server announces app.test:2122, Conduit has a site on
2122) and lists a directory with ftplib. Active mode (the server connects back to the client) does not work through
a proxy. SFTP is not FTP: see below.
SFTP and SSH
SFTP, scp, rsync -e ssh and git over SSH are all SSH, a TCP stream:
sites:
- port: 22
tcp: {targets: ["ssh.internal:22"]}
The test checks that the identification strings of client and server cross the proxy untouched. The client sees the upstream’s
host key, so known_hosts entries made through Conduit carry the backend’s key: keep one backend or give all backends the same host key.
If Conduit’s own host needs SSH on port 22, put Conduit on another port (ssh -p 2222).
What is not supported
These are gaps rather than choices; each is a candidate feature:
- UDP proxying (WebRTC media, QUIC, DNS, syslog).
- An access filter (IP allow/deny) on TCP sites, and TLS to the upstream of a TCP site (TLS termination on the client side works, see TLS on a TCP site).
- Writing the PROXY protocol to an HTTP upstream (receiving it works on plain HTTP, TLS and
tcpsites, see PROXY protocol). - Port ranges (FTP passive ports need one site each).
- Active health probes that speak h2c or TLS (a TLS upstream is probed by connecting only), or a TCP-level probe for TCP sites.
- A per-route custom CA for
upstreamTls(onlyverify: falseor the process-wide roots: the system store, or the file inSSL_CERT_FILE). The host needs a non-empty root store even withverify: false; see Upstream TLS verification.