Product

Product Features How to Compare Docs Screenshots Why

Start here

Getting started Download Guides Frequently asked questions

More

Security Support Roadmap About

Traffic

TCP and UDP proxying

Everything else on this site is about web traffic. This page is about the rest: a protocol that speaks for itself, where all you need is a port to listen on and somewhere to send the connections.

lb-01.example.net/lb/streams
The TCP and UDP page. One row per service.
The TCP and UDP page. One row per service.

How it differs from a site

There are no paths, no error pages and no redirects, because those are web ideas and this is not the web. What you get is a port to listen on and a pool to send connections to. Health checks still apply, and so do the balancing methods.

Making one

  1. Make a pool with the backend servers in it. Stream pools are separate from the pools sites use.
  2. Go to TCP & UDP and press Add one.
  3. Choose TCP or UDP. If you are not sure, it is TCP.
  4. Say which port to listen on.
  5. Choose the pool, then save and apply.

Pools are kept separate

Pools used here are separate from the pools used by sites, even when the servers in them are the same machines. That is a rule in nginx, not a choice made here, so you will see the same addresses listed twice and that is correct.

Passing on the visitor's address

By default your backend sees the connection as coming from the load balancer, because it is. If your application needs the real client address, turn on the proxy protocol setting.

Only if the backend understands it

Proxy protocol adds a short header before the connection data. A backend that does not expect it 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.

What people actually use this for

ServiceProtocolNotes
PostgreSQL or MySQL read replicasTCPUse least connections. Long lived connections make round robin uneven.
SMTP, IMAP or POP3TCPProxy protocol if your mail server supports it, so logs show the real sender.
DNS resolversTCP and UDPTwo services, one per protocol, pointing at the same pool.
Game serversUDPWatch the health check type. A connection check means little for UDP.
RedisTCPOnly for read replicas. Balancing writes across a cluster is not something a proxy can fix.

Common questions

Can I terminate TLS for a stream service?

Yes, nginx is built with the stream TLS module. You pick a certificate the same way a site does.

Does the health checker work for UDP?

It can open a socket and it can check a TCP port on the same host. A meaningful UDP health check depends entirely on the protocol, so check a companion TCP port where one exists.

Can two services share a port?

No. One listen port belongs to one service, the same as in nginx itself.

Step by step instructions

The how to section has searchable, task shaped answers. Search it for tcp.

Related features

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.