docker编译运行
创建Dockerfile文件
FROM haproxy:2.6.8
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
编译docker镜像
docker build -t my-haproxy .
测试配置文件
docker run -it --rm --name haproxy-syntax-check my-haproxy haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg
haproxy在tcp模式下转发客户端的ip
forwardfor 仅在http模式下有效,主要是在http头添加 x-forwarded-for 数据
在tcp模式下就无法获知源的ip。
较新的信息 proxy-protocol协议也是http模式
https://www.haproxy.com/documentation/hapee/latest/load-balancing/client-ip-preservation/enable-proxy-protocol/
frontend mywebsite
bind :80 accept-proxy
default_backend webservers
backend webservers
balance roundrobin
server s1 192.168.56.20:3000 check send-proxy
server s2 192.168.56.21:3000 check send-proxy
较旧的信息(2014年) 根据
centos5 - haproxy forwardfor ignored while in tcp mode - Server Fault
x-forwarded-for is an HTTP header field, so has nothing to do with the transport layer (TCP). Usually web proxies insert the x-forwarded-for data.
If you want to have the source IP when balancing at transport layer, then you need to compile haproxy with TPROXY support. See: Configure HAProxy with TPROXY kernel for full transparent proxy
But note that the current Linux kernel has TPROXY support by default (It has done since 2.6.28), so you may be able to skip the kernel step described in the above blog post if your kernel version > 2.6.28.
双域名问题