Apache: PROXY protocol for Amazon ELB (Elastic Load Balancing)

If you want to use Apache 2.2 / 2.4 behind a Amazon ELB (Elastic Load Balancing), HAproxy, Stunnel, Stud o anything similar, you will have seen that in the logs appears IP of ELB instead of the remote client, and filter by IP is a double problem.

The module “remoteip” does not solve the problem. Amazon ELB, HAProxy and others support “PROXY protocol”, that helps to fix this issues working behind proxys.

The protocol look similar to:

PROXY TCP4 56324 443\r\n
GET / HTTP/1.1\r\n
Host: www.acme.com\r\n
Accept: */*\r\n
Connection: close\r\n

But Apache currently does not support out-of-the-box. So following the philosophy of Do-It-Yourself, here is the source code (beta):

mod_myfixip.c in Github (for Apache 2.4)
mod_myfixip.c in Github (for Apache 2.2)

UPDATE (2015.01.17): Seems that AWS-ELB don’t always send PROXY header in only one packet / TCP-frame (in some cases data is received fragmented, now the module handle this behavior).

ElasticLoadBalancing: Enable Proxy Protocol
PROXY protocol


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s

A %d blogueros les gusta esto: