Product

Product Features How to Compare Docs Screenshots Why

Start here

Getting started Download Guides Frequently asked questions

More

Security Support Roadmap About

TCP and UDP

7 answers

Balancing things that are not web traffic.

Looking for something specific

The searchable index covers all 326 answers at once and filters as you type.

115 Load balance a database or a mail server
  1. Make a pool with the backend servers in it. Stream pools are separate from the pools sites use.
  2. TCP & UDP, Add one.
  3. Choose TCP, set the listen port, choose the pool.
  4. Save and apply.

For long lived connections such as a database, least connections spreads load better than round robin.

tcpdatabasepostgresmysqlsmtp
116 Pass the real client address to a TCP backend

Turn on the proxy protocol setting, but only if the backend understands it. A backend that does not will fail to read the connection at all, and the failure looks like the service being completely broken rather than like a setting being wrong.

proxy protocolclient ipreal address
117 Balance a UDP service

Same steps, choose UDP instead of TCP. Health checking UDP is genuinely hard, so where the same host exposes a TCP port, check that instead.

udpdnsgame serversyslog
118 Terminate TLS for a TCP service

nginx is built with the stream TLS module, so you pick a certificate the same way a site does. Useful for putting TLS in front of something that does not speak it, such as an internal service.

stream tlssslterminate
201 Only let certain addresses connect to a TCP service

TCP & UDP, open the listener, and set Who can connect to an access list. Make the list first under Zones & Access, Access lists.

This matters more for TCP than for a website. A database port open to the internet is found by a scanner within hours, and unlike a web request there is no application login page in front of it doing rate limiting for you.

tcp access listdatabase portrestrictfirewallstream allow
202 Set a timeout on an idle TCP connection

TCP & UDP, open the listener, and use Idle timeout and Connect timeout.

Raise the idle timeout for a database connection pool, which holds connections open for a long time on purpose and will reconnect constantly if you cut it too short. Keep the connect timeout short so a dead backend is noticed quickly.

stream timeoutidledatabase poolconnection drop
203 Accept the PROXY protocol from something in front

TCP & UDP, open the listener, and tick Expect the PROXY protocol from whatever is in front.

Only tick it if the thing in front really sends it. A listener expecting the PROXY protocol header treats a normal connection as malformed and drops it, which looks exactly like a broken backend and takes a while to work out.

proxy protocolreal client ip tcpcloud load balancerv2

Two fresh servers is all it takes

Ubuntu 22.04 or newer, root access, and about twenty minutes. The installer does the rest and it is safe to run twice.