haproxy ist ein Load-Balancer (vor allem für HTTP(s) und TCP - nicht UDP) der in der 'Programmiersprache C geschrieben ist. Er wird aufgrund seiner Performanz von großen Webseiten eingesetzt.
Diese Seite bezieht sich auf haproxy version 1.7.
Es sollte möglichst aktuelle Versionen benutzt werden, eine extra Paketquelle bietet sich an um die aktuellste stabile Version zu erhalten die noch nicht in der Distribution enthalten ist: Für Debian z.B. die HAProxy packages.
…
Eine Beispiel-Webapp „WEBAPP1“, drei Server/nodes (10.0.0.1, 10.0.0.2, 10.0.0.3), ein SSL-Bundle liegt in /etc/ssl/private/WEBAPP1-certbundle-crt-chain-and-privkey.pem .
# Sample Config für haproxy 1.7.x - see documentation: https://cbonte.github.io/haproxy-dconv/1.7/configuration.html 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 # Default SSL material locations ca-base /etc/ssl/certs crt-base /etc/ssl/private # default ciphers client <-> haproxy ssl-default-bind-ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA:EECDH:EDH+AESGCM:EDH:ECDH+AESGCM:ECDH+AES:ECDH:HIGH:MEDIUM:!RC4:!3DES:!CAMELLIA:!SEED:!aNULL:!MD5:!eNULL:!LOW:!EXP:!DSS:!PSK:!SRP # default ciphers haproxy <-> server ssl-default-server-ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA:EECDH:EDH+AESGCM:EDH:ECDH+AESGCM:ECDH+AES:ECDH:HIGH:MEDIUM:!RC4:!3DES:!CAMELLIA:!SEED:!aNULL:!MD5:!eNULL:!LOW:!EXP:!DSS:!PSK:!SRP ssl-default-bind-options no-sslv3 no-tls-tickets # SSL DH 2048 (default is 1024 but with warning): tune.ssl.default-dh-param 2048 defaults log global mode http option httplog option dontlognull timeout connect 5000ms retries 2 timeout client 10000ms timeout server 10000ms timeout queue 60000ms timeout http-request 15000ms timeout http-keep-alive 15000ms # assign client to other node if his current node dies: option redispatch # insert X-Forwarted-For-Header with client-IP: option forwardfor # close server-conn, but leave client-facing conn open ( https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#option%20http-server-close ): option http-server-close 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 #frontend WEBAPP1-http # bind *:80 # default_backend WEBAPP1 # #frontend WEBAPP1-https # bind *:443 ssl crt /etc/ssl/private/WEBAPP1-certbundle-crt-chain-and-privkey.pem # default_backend WEBAPP1 # # HSTS: # rspadd Strict-Transport-Security:\ max-age=31536000 frontend WEBAPP1-http-with-redirect-to-https bind *:80 bind *:443 ssl crt /etc/ssl/private/WEBAPP1-certbundle-crt-chain-and-privkey.pem # Redirect if HTTPS is *not* used redirect scheme https code 301 if !{ ssl_fc } # HSTS: rspadd Strict-Transport-Security:\ max-age=31536000 # haproxy stats: stats enable stats uri /haproxy?stats stats realm haproxy stats auth MEIN_BENUTZER:GEHEIMES_Passwort # stats auth Another_User:passwd default_backend WEBAPP1 backend WEBAPP1 balance roundrobin # other options: static Round Robin (static-rr), Least Connections (leastconn), Source (source), URI (uri) and URL parameter (url_param). # "maxconn 200" limits simultaneous requests to 200, see: https://www.haproxy.com/de/blog/play_with_maxconn_avoid_server_slowness_or_crash/ server node1 10.0.0.1:80 check maxconn 200 server node2 10.0.0.2:80 check maxconn 200 server node3 10.0.0.3:80 check maxconn 200 # Nodes with SSL and verification of SSL-Traffic (possible: none|all) # server node1 10.0.0.1:443 check ssl verify all maxconn 200 # server node2 10.0.0.2:443 check ssl verify all maxconn 200 # server node3 10.0.0.1:443 check ssl verify all maxconn 200
Eine einzige Konfigurationsdatei haproxy.conf wäre allen Einstellungen ist nicht ideal für eine Automatisierung. Die Lösung ist der Parameter „-f“, damit können Verzeichnisnamen angeben werden die dann *.cfg-Dateien in alphabetischer Reihenfolge einliest (siehe „-f <cfgfile|cfgdir>“ in http://cbonte.github.io/haproxy-dconv/1.7/management.html ).
In der Datei /etc/default/haproxy
:
# Change the config file location if needed, only *.cfg-files are loaded in lexical order! CONFIG="/etc/haproxy/conf.d"
Nun legen wir die Config-Dateien in /etc/haproxy/conf.d mit Endung .cfg ab und nach Neustart werden die von dort geladen.
die globale Konfiguration sollte als erstes eingelesen werden, z.B. bei einer Benennnung mit
00_haproxy.cfg
, weitere Dateien könnten dann 50_backend1.cfg
, 50_backend2.cfg usw. heißen.
testen, Quelle: https://stuff-things.net/2016/11/30/haproxy-sni/
https://serverfault.com/questions/662662/haproxy-with-sni-and-different-ssl-settings
Quelle: https://discourse.haproxy.org/t/haproxy-1-6-with-sni-and-different-ssl-settings-per-hostname/698
acl domain_strong_SSL req_ssl_sni -i www.superSecure.com acl domain_standard_SSL req_ssl_sni -i www.normal.com use_backend strong_SSL if domain_strong_SSL use_backend standard_SSL if domain_standard_SSL frontend strong_SSL bind *:443 ssl crt /path/to/cert force-tlsv12 ciphers MY_STRONG_CIPHERSTRING [...] frontend standard_SSL bind *:443 ssl crt /path/to/cert force-tlsv12 ciphers MY_RELAXED_CIPHERSTRING [...]
…die integrierte Stats-Seite (s.o.)
apt install hatop
in der haproxy.cfg den stats-socket:
stats socket /run/haproxy/admin.sock mode 660 level admin
und los gehts:
hatop -s /run/haproxy/admin.sock