User Tools

Site Tools


wiki:proxy:haproxy:installation_config

This is an old revision of the document!


Installation et configuration de base de HAProxy pour un reverse proxy simple

Le but est de rediriger les requetes http par dns.

Installation (Debian12)

Simple package à installer sur le serveur.

sudo apt install haproxy

Configuration de base

La configuration de HAProxy se fait via le fichier de configuration haproxy.cfg situé à /etc/haproxy/haproxy.cfg

vim /etc/haproxy/haproxy.cfg

Le frontend

On rajoute un front end en mode http

frontend http-in
    bind *:80
    mode http
    
    acl myapp_front1 hdr_dom(host) -i sous-domaine1.mon-domaine.fr
    use_backend load1 if myapp_front1

    acl myapp_front2 hdr_dom(host) -i sous-domaine1.mon-domaine.fr
    use_backend load2 if myapp_front2

Le backend

  acl myapp_front1 hdr_dom(host) -i test1.hugo-mattaliano.fr
  use_backend load1 if myapp_front1
  acl myapp_front2 hdr_dom(host) -i test2.hugo-mattaliano.fr
  use_backend load2 if myapp_front2

backend load1

    server serveur_apache 172.16.0.101:80

backend load2

    server serveur_nginx 172.16.0.102:80

Test de la configuration

Tester la configuration avant de relancer haproxy pour eviter les erreurs.

haproxy -c -f /etc/haproxy/haproxy.cfg

Si tout est bon, relancer le service.

sudo systemctl restart haproxy
wiki/proxy/haproxy/installation_config.1741439400.txt.gz · Last modified: 2025/03/08 14:10 by hmattaliano