haproxy 前端没有443端口如何平衡后端443?

haproxy 前端没有443端口如何平衡后端443?

我的 haproxy 配置是:

# Configuration for 678da17a-5c8f-4d2b-9431-f3019aae9726
global
    daemon
    user nobody
    group haproxy
    log /dev/log local0 debug alert
    log /dev/log local1 notice alert
    maxconn 2000
    stats socket /var/lib/neutron/lbaas/v2/678da17a-5c8f-4d2b-9431-f3019aae9726/haproxy_stats.sock mode 0666 level user

defaults
    log global
    retries 3
    option redispatch
    timeout connect 5000
    timeout client 50000
    timeout server 50000

frontend 8e85521c-f92b-401a-a72f-9f3d9dbd9deb
    option tcplog
    bind 123.44.44.44:5200
    mode tcp
    default_backend 46a948a1-1043-437d-83d0-e25acf0c94fd

backend 46a948a1-1043-437d-83d0-e25acf0c94fd
    mode tcp
    balance roundrobin
    server 9add0118-0255-4ee3-998a-875fb251624b 123.23.23.23:443 weight 1

我想配置前端使用 5200 端口来访问后端服务器 123.23.23.23:443。但是当我请求https://123.44.44.44:5200,请求更改为https://123.44.44.44/index.html。导致请求失败。为什么会这样?

答案1

HAProxy 正在请求https://123.44.44.44/从后端。这是根目录,而不是实际的文件,因此后端通过将浏览器重定向到默认文件 (index.html) 来响应,从后端的角度来看,该文件位于https://123.44.44.44/index.html。使用浏览器中的开发人员工具确认这一点,您可能会看到 301 代码。

至少有两种方法可以解决这个问题。第一种是在后端 Web 服务器上 - 除非您对其进行配置,否则后端对端口 5200 一无所知。第二种是在 HAProxy 中通过重写标头来实现Location:,例如

http-request replace-header Location ^https://123.44.44.44/(.*)$ https://123.44.44.44:5200/\1

如果您使用 HAProxy 方法,请注意您需要分别对 IP 地址和域名执行此操作(如果您将使用两者进行访问并且希望两者都能正常工作)。

相关内容