Was sind HAProxy ACLs?

In HAProxy ermöglichen ACLs, eingehende Anfragen für Routing, Sicherheit oder Umleitungen zu prüfen.

Grundlegende Syntax

acl <acl_name> <kriterium> [flags] <wert>

Häufige Anwendungsfälle

1. Host-basiertes Routing

frontend main_frontend
    bind *:80
    acl is_blog hdr(host) -i blog.beispiel.com
    use_backend blog_servers if is_blog

2. Pfad-basiertes Routing

frontend main_frontend
    bind *:80
    acl app_api path_beg /api/
    use_backend api_servers if app_api

3. IP-Blockierung

frontend main_frontend
    bind *:80
    acl blocked_ip src 203.0.113.50
    http-request deny if blocked_ip

4. HTTP zu HTTPS Umleitung

frontend http_in
    bind *:80
    http-request redirect scheme https code 301 if !{ ssl_fc }

5. Routing nach User-Agent

frontend main_frontend
    bind *:80
    acl is_mobile hdr_sub(User-Agent) -i android iphone
    use_backend mobile_servers if is_mobile

Zusammenfassung

  • Testen Sie die Syntax immer mit haproxy -c, bevor Sie neu laden.

Verwandte Artikel