首页 > 解决方案 > HAProxy tcp模式源客户端ip

问题描述

我在 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
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

defaults
    log global
    retries 2
    option  dontlognull
    timeout connect 10000
    timeout server 600000
    timeout client 600000

frontend https
    bind 5.x.x.x:443
    default_backend https

backend https
    mode tcp
    balance roundrobin
    option tcp-check
    server traefik 192.168.128.5:9443 check fall 3 rise 2

它按预期工作,后端服务器“traefik”正在对请求进行 SSL 终止。

问题是我在后端服务器中获得的客户端源 IP 是 HAProxy 的 IP,我想将源 IP 传递给后端服务器。

有可能吗?因为我尝试了我在互联网上看到的所有选项。

谢谢。

标签: linuxnetworkinghaproxy

解决方案


最后,解决方案是使用https://www.haproxy.com/blog/haproxy/proxy-protocol/,因为它受到 HAProxy 和 traefik 的支持。

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

defaults
    log global
    retries 2
    option  dontlognull
    timeout connect 10000
    timeout server 600000
    timeout client 600000

frontend https
    bind 5.x.x.x:443
    default_backend https

backend https
    mode tcp
    balance roundrobin
    option tcp-check
    server traefik 192.168.128.5:9443 check fall 3 rise 2 send-proxy

并启用 traefik 的入口点代理协议,如下所述:https ://docs.traefik.io/configuration/entrypoints/#proxyprotocol


推荐阅读