我有一個包含兩個後端伺服器的配置,我需要將 301 重新導向到每個具有 HTTP 內部 URL 的伺服器。很難使用 SSL,因為我無法在該設定中的報表伺服器上安裝 SSL。另外,我無法使用虛擬域和共享 IP 來重定向流量,因為查看報告時報告檢視器存在一些內部問題。我只需要將流量重定向到後端伺服器,最好使用內部 URL,但 IP 也可以。
目前我知道如何對一台特定主機執行此操作,但不知道如何對當前伺服器執行此操作。
配置:後端的主動/被動配置。
HA-代理版本 2.0.29-0ubuntu1
Ubuntu 20.04.5 LTS
Keepalived v2.0.19
frontend raporty bind 192.168.0..108:80 bind 192.168.0.108:443 ssl crt /etc/ssl/certs/haproxy.pem default_backend reportserver option forwardfor backend reportserver mode http balance roundrobin option httpchk uri /reports http-check expect status 401 http-response set-header X-Server %s http-request redirect code 301 location http://sql02.domain.local%[capture.req.uri] server sql01 192.168.0.11:80 check check fall 5 server sql02 192.168.0.111:80 check check fall 5 http-response set-header X-Server %s
答案1
這是透過使用 ACL 和 srv_is_up 參數來管理的。
frontend raporty
bind 192.168.0.108:80
bind 192.168.0.108:443 ssl crt /etc/ssl/certs/haproxy.pem
http-response set-header X-Server %s
http-response set-header Host %s
default_backend reportserver
option forwardfor
backend reportserver
mode http
balance roundrobin
option httpchk uri /reports
http-check expect status 401
acl asql01 srv_is_up(reportserver/sql01)
acl asql02 srv_is_up(reportserver/sql02)
http-request set-header Host %s
http-response set-header Host %s
http-request redirect code 301 location http://sql01.domain.local%[capture.req.uri] if asql01
http-request redirect code 301 location http://sql02.domain.local%[capture.req.uri] if asql02
server sql01 sql01.domain.local:80 check check fall 5
server sql02 sql02.domain.local:80 check check fall 5
http-response set-header X-Server %s