HAProxy stands for High Availability Proxy, is a popular open source software.
Improve performance and reliability of a server by distributing workload across multiple server
NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more.
simple configuration
simple control and monitoring
not suited for complex or large system
no status on connection rate
NGINX Plus includes exclusive features not available in NGINX Open Source and award-winning support.
Exclusive features includes active health checks, session persistence, JWT authentication, and more.
HaProxy | NGINX | |
---|---|---|
Full web server |
|
|
Concurrency |
|
|
Load balancer |
|
|
SSL offloading |
|
|
Able to run in windows | ||
Metrics | 61 different metrics | 7 different metrics |
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
log 127.0.0.1 local2 #Log configuration
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy #Haproxy running under user and group "haproxy"
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
#---------------------------------------------------------------------
#HAProxy Monitoring Config
#---------------------------------------------------------------------
listen haproxy3-monitoring *:8080 #Haproxy Monitoring run on port 8080
mode http
option forwardfor
option httpclose
stats enable
stats show-legends
stats refresh 5s
stats uri /stats #URL for HAProxy monitoring
stats realm Haproxy\ Statistics
stats auth howtoforge:howtoforge #User and Password for login to the monitoring dashboard
stats admin if TRUE
default_backend app-main #This is optionally for monitoring backend
#---------------------------------------------------------------------
# FrontEnd Configuration
#---------------------------------------------------------------------
frontend main
bind *:80
option http-server-close
option forwardfor
default_backend app-main
#---------------------------------------------------------------------
# BackEnd roundrobin as balance algorithm
#---------------------------------------------------------------------
backend app-main
balance roundrobin #Balance algorithm
option httpchk HEAD / HTTP/1.1\r\nHost:\ localhost #Check the server application is up and healty - 200 status code
server server1 172.20.32.109:80 check
server server2 172.20.32.110:80 check
http {
server {
listen 80;
location / {
proxy_pass http://backend;
}
}
upstream backend {
server 172.20.32.109:80;
server 172.20.32.110:80;
}
}
NGINX
HAProxy
HAProxy stats page
NGINX status page
username: howtoforge
Active connections – Number of all open connections. This doesn’t mean number of users. A single user, for a single pageview can open many concurrent connections to your server.
Server accepts handled requests – This shows three values.
First is total accepted connections.
Second is total handled connections. Usually first 2 values are same.
Third value is number of and handles requests. This is usually greater than second value.
Dividing third-value by second-one will give you number of requests per connection handled by Nginx. In above example, 10993/7368, 1.49 requests per connections.
Reading – nginx reads request header
Writing – nginx reads request body, processes request, or writes response to a client
Waiting – keep-alive connections, actually it is active – (reading + writing).This value depends on keepalive-timeout. Do not confuse non-zero waiting value for poor performance. It can be ignored. Although, you can force zero waiting by setting keepalive_timeout 0;
Layer 4 (TCP) and Layer 7 (HTTP) load balancing
URL rewriting
Rate limiting
SSL/TLS termination
Gzip compression
Proxy Protocol support
Health checking
Connection and HTTP message logging
HTTP/2