Debian – HAproxy

Vytvoření HA nebo reverzní proxy na linuxové platformě s pomocí HAproxy:

– instalace (více zde: https://haproxy.debian.net/)

Instalace HAproxy
# apt-get update
# apt-get install haproxy

– konfigurace jednoduché reverzní proxy (bez SSL), jedním serverem

Konfigurace HAproxy
#HAproxy jako reverzni proxy

global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
maxconn 2048

defaults
log global
mode http
option httplog
option dontlognull
option forwardfor
option http-server-close
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

#FRONT END SERVER – STATS

frontend www_frontend_stats
bind *:8181
stats enable
stats uri /
acl host_web0 hdr(host) -i localhost
use_backend web0_cluster if host_web0

# FRONT END SERVER – HTTP

frontend www_frontend
bind *:80

reqadd X-Forwarded-Proto:\ http

acl host_web1 hdr(host) -i elvisek.cz www.elvisek.cz
acl host_web2 hdr(host) -i elvisek.eu www.elvisek.eu

use_backend web1_cluster if host_web1
use_backend web2_cluster if host_web2

# default_backend web1_cluster

# BACK END SERVER – HTTP

backend web0_cluster
# localhost
balance leastconn
http-request set-header X-Client-IP %[src] server websrv_127.0.0.1 127.0.0.1:80 check

backend web1_cluster
# web server 1
balance leastconn
http-request set-header X-Client-IP %[src] server websrv_192.168.1.11 192.168.1.11:80 check

backend web2_cluster
# web server 2
balance leastconn
http-request set-header X-Client-IP %[src] server websrv_192.168.1.12 192.168.1.12:80 check
# server websrv_192.168.1.13 192.168.1.13:80 check

Přímý odkaz na tento článek: https://www.elvisek.cz/2017/07/debian-haproxy/

Napsat komentář

Váš email nebude zvežejněn.