How to setup HAProxy as Load Balancer for Nginx on CentOS 7

Опубликовано: 05 Октябрь 2024
на канале: Technotes ID
455
3

HAProxy or High Availability Proxy is an open source TCP and HTTP load balancer and proxy server software. HAProxy has been written by Willy Tarreau in C, it supports SSL, compressions, keep-alive, custom log formats and header rewriting. HAProxy is a fast and lightweight proxy server and load balancer with a small memory footprint and low CPU usage. It is used by large sites like Github, StackOverflow, Reddit, Tumblr, Twitter and others. It has become the most popular software load balancer and proxy server in the past years.

config HAproxy below :

global
log 127.0.0.1 local0
log 127.0.0.1 local1 debug
maxconn 45000 # Total Max Connections.
daemon
nbproc 1 # Number of processing cores.
defaults
timeout server 86400000
timeout connect 86400000
timeout client 86400000
timeout queue 1000s

[HTTP Site Configuration]
listen http_web 192.168.10.100:80
mode http
balance roundrobin # Load Balancing algorithm
option httpchk
option forwardfor
server server1 192.168.10.101:80 weight 1 maxconn 512 check
server server2 192.168.10.102:80 weight 1 maxconn 512 check

[HTTPS Site Configuration]
listen https_web 192.168.10.100:443
mode tcp
balance source# Load Balancing algorithm
reqadd X-Forwarded-Proto: http
server server1 192.168.10.101:443 weight 1 maxconn 512 check
server server2 192.168.10.102:443 weight 1 maxconn 512 check