By clicking or navigating this website site, you agree to allow our collection of information on Scaleway to offer you an optimal user experience and to keep track of statistics through cookies. Learn more about our Cookie Policy.

How to use the Proxy protocol v2 with Load Balancer

Proxy Protocol V2 Overview

The PROXY Protocol allows an application, like a web server like Apache or Nginx, to retrieve client information of a user passing via a load balanced infrastructure.

The protocol transports connection information including the originating IP address, the proxy server IP address, and both ports.

This information can be useful for automatic delivery of localized contents, blacklisting of abusive users or for logging purposes.

4 . Set the IP address of the Load Balancer with the set_real_ip_from directive in the server {} block:

set_real_ip_from 51.159.26.16;

5 . To change the IP address of the load balancer to the clients IP address, received from the PROXY protocol header, specify in the server {} block the proxy_protocol parameter to the real_ip_header directive:

real_ip_header proxy_protocol;

6 . As the clients IP address is now known to Nginx, configure the correct logging of it. Set the proxy_set_header directive with the $proxy_protocol_addr variable in the http {} block:

Important: Once ProxyProtocol is enabled the Nginx virtual host will no longer accept direct connections.

Configuring Proxy Protocol in Apache Web Server

The Proxy Protocol support in Apache is still in an early stage. It is currently not natively supported with the Apache version provided by Ubuntu. An unofficial plugin is available for Apache versions prior to 2.4.30. To use it, follow these steps:

Important: Once ProxyProtocol is enabled the Apache virtual host will no longer accept direct connections.

Configuring Proxy Protocol in Apache with mod_remoteip

Important: An Apache version >= 2.4.30 is required to use mod_remoteip. This version is currently not yet available in Ubuntu’s repositories, and you have to install it by yourself. Use it only if you know what you are doing.

1 . Enable the module remoteip:

a2enmod remoteip

2 . Configure the Apache virtual host configuration:

<VirtualHost *:80>
...
RemoteIPProxyProtocol On
...
</VirtualHost>

3 . Restart the Apache web server:

apache2ctl restart

Important: Once ProxyProtocol is enabled the Apache virtual host will no longer accept direct connections.