在 HAProxy 中重定向特定的 URL

问题描述 投票:0回答:0

我的服务器前面有一个 HAProxy。

这是它的配置:

global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

    # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

    # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
        ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
        ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
        ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets

defaults
    log global
    mode    http
    option  httplog
    option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000
    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 http
   bind *:80
   mode tcp
   redirect scheme https code 301 if !{ ssl_fc }
   default_backend http

frontend https
    bind *:443
    mode tcp
    default_backend https

backend https
    balance roundrobin
    mode tcp
    server worker1 172.16.0.172:32443 check
    server worker2 172.16.0.196:32443 check
    server worker3 172.16.0.153:32443 check
    server worker4 172.16.0.19:32443 check

backend http
    balance roundrobin
    mode tcp
    server worker1 172.16.0.172:32080 check
    server worker2 172.16.0.196:32080 check
    server worker3 172.16.0.153:32080 check
    server worker4 172.16.0.19:32080 check


frontend stats
   option http-use-htx
   stats enable
   stats uri /stats
   stats refresh 10s

现在我想要这个 (

default_backend
) 但也添加一个规则将
xxx.company.com
重定向到 another backend(并将除此之外的所有内容重定向到默认后端)。

我怎样才能做到这一点?


我尝试过的解决方案(无效):

frontend http
   bind *:80
   mode tcp
   acl test_host hdr(host) -i xxx.company.com
   use_backend xxx if test_host
   default_backend http

backend xxx
    balance roundrobin
    mode tcp
    server nginx 172.16.0.32:80 check

frontend http
   bind *:80
   mode tcp
   use_backend xxx if { hdr_dom(Host) -i xxx.company.com }
   default_backend http

backend xxx
    mode tcp
    server nginx 172.16.0.32:80 check

HA代理版本:

HAProxy version 2.4.19-1ppa1~focal

haproxy
© www.soinside.com 2019 - 2024. All rights reserved.