Load balancing
Passive FTP
In passive mode File Transfer Protocol (FTP), the client initiates all connections to the server, making it compatible with intermediary proxies and firewalls. In contrast, active mode FTP has the server initiate connections to the client, and this is often blocked. For this reason, passive FTP is recommended over active FTP.
The passive configuration documented on this page supports not only FTP but also FTPS. It does not support SFTP.
Configure FTP servers Jump to heading
Perform these steps on the FTP servers. Consult the documentation for your FTP server.
-
Configure your FTP server to use passive mode. It should return the IP address of the load balancer as the advertised address of the FTP service. Later, we will configure the load balancer to listen at this address.
For example, on a vsftpd FTP server, set the
pasv_address
variable to the IP address of the FTP service configured on the load balancer:pasv_address=192.168.0.100 # IP of ftp.example.com
pasv_address=192.168.0.100 # IP of ftp.example.com
-
Configure the passive FTP port range on the FTP server. For example, you might use the port range
50000-50010
, or you can use a larger range. Be careful to limit the port range to prevent file descriptor exhaustion.
Configure the load balancer Jump to heading
-
Update your
frontend
section in the following ways:- In the
bind
directives, set the IP addresses to match the advertised FTP site IP (thepasv_address
on the FTP server). - In the second
bind
directive, enter the port range your FTP servers use for data connections (for example,50000-50010
).
haproxyfrontend ftp_femode tcpoption tcploglog globalbind 192.168.0.100:21 name ftp-controlbind 192.168.0.100:50000-50010 name ftp-datadefault_backend ftp_servershaproxyfrontend ftp_femode tcpoption tcploglog globalbind 192.168.0.100:21 name ftp-controlbind 192.168.0.100:50000-50010 name ftp-datadefault_backend ftp_servers - In the
-
Update your
backend
section in the following ways:- Configure the
server
directives to use the FTP servers’ IP addresses. Below, we use the FTP servers at192.168.1.10
and192.168.1.11
. - Add
stick-table
andstick on
directives to enable session persistence. This will route a client to the same server for both control and data. It also provides support for FTPS. See Session persistence.
haproxybackend ftp_serversmode tcpbalance leastconnstick-table type ip size 100k expire 1hstick on srcserver ftp-server1 192.168.1.10 check port 21server ftp-server2 192.168.1.11 check port 21haproxybackend ftp_serversmode tcpbalance leastconnstick-table type ip size 100k expire 1hstick on srcserver ftp-server1 192.168.1.10 check port 21server ftp-server2 192.168.1.11 check port 21 - Configure the
See also Jump to heading
Do you have any suggestions on how we can improve the content of this page?