Ignorer le port dans le Host header de HAProxy
Prometheus envoie des requêtes avec le header Host: <host>:<port>
, or haproxy ne trouve pas le backend correspondant. Il va en effet regarder si <host>:<port>
correspond à <host>
.
Par exemple:
acl probe-01-first-neutri-net-acl hdr(host) probe-01.first.neutri.net
use_backend probe-01-first-neutri-net-backend if probe-01-first-neutri-net-acl
Ces deux lignes disent à haproxy d'utiliser le backend probe-01-first-neutri-net-backend
si le header Host
correspond à probe-01.first.neutri.net
. Comme le header Host
de Prometheus contient probe-01.first.neutri.net:443
, il ne trouve pas le backend et renvoie une erreur 503.
La solution est donnée ici: https://discourse.haproxy.org/t/strip-port-in-host-header/4414/8
acl probe-01-first-neutri-net-acl hdr(host),field(1,:) probe-01.first.neutri.net
use_backend probe-01-first-neutri-net-backend if probe-01-first-neutri-net-acl
HAProxy ne va regarder que la partie du header Host
qui se trouve avant les :
, et de ce fait le backend va correspondre.