# The PROXY protocol on a port

When a load balancer stands in front of the server, every connection reaches the server from the balancer's address. The server then cannot tell users apart by address: the log shows one address for everybody, rules by address stop working, and one user who hammers the server gets the balancer banned, and with it everybody.

The PROXY protocol solves this. The balancer, as the first thing on each new connection, sends one short header that says where the connection really comes from. The server reads it and treats the connection as coming from there.

It works for every protocol, because it comes before the protocol starts: FTP, SFTP, HTTPS.

## Turning it on

On the **Advanced** tab of the listener in [IP / Servers](Ports.md):

| Setting | For a balancer that sends |
|---|---|
| **Read proxy protocol header info from connecting socket (v1)** | version 1, a line of text |
| **Read proxy protocol header info from connecting socket (v2)** | version 2, the binary form |

Turn on the one the balancer sends. **Never both**, and never one that the balancer does not send: the server then waits for a header that does not come, or reads the first bytes of the real conversation as a header, and every connection fails.

Turn it on at both ends at the same moment: the balancer starts sending when the listener starts expecting.

## Only for the balancer

> [!WARNING]
> A listener that reads the header believes it from anyone. Whoever can connect to it directly can claim any address, and so slip past rules by address, or get somebody else's address banned.

Make sure nothing but the balancer can reach the listener:

- give the listener an address of the internal network that only the balancer reaches, and
- close its port to everything else in the firewall of the machine or the network.

The listener's own [IP restrictions](Ports-IP-Restrictions.md) cannot do this. Once the header is read, they are checked against the address **in the header**, the user's, which is what you want for rules about users and useless for telling the balancer from an impostor.

Keep a second listener **without** the header for yourself, inside the network, to reach the server when the balancer is down.

## Who can send it

| In front of the server | Setting there |
|---|---|
| CrushBalance | sends it when the target is set to expect it |
| HAProxy | `send-proxy` (v1) or `send-proxy-v2` on the server line |
| nginx, stream module | `proxy_protocol on;` |
| AWS Network Load Balancer | "Proxy protocol v2" on the target group |
| F5, Citrix ADC and others | an option of the pool or profile, often an iRule or a policy |

A plain TCP balancer is what this is for. A balancer that speaks HTTP itself usually says who the client is with a header of HTTP instead: see [Behind a proxy](Ports-Behind-a-Proxy.md).

## Sending it on

CrushMFT can also **send** the header, where it passes connections on itself: **Send IP to other side using Proxy Protocol V1** on a [port forwarding](Ports-Port-Forward.md) listener.

## Things to know

- Health checks of the balancer must send the header too, or use a listener without it. A check that just opens and closes the port is logged as a broken header.
- [HTTP/3](Ports-HTTP3.md) is not started on a listener that expects the header.
- After turning it on, look at [Connected users](Admin-Sessions.md): the sessions should show the users' own addresses. If they show the balancer's, the header is not being read; if nobody can connect, it is expected and not sent.
