在运行在HAProxy上的K8S实例上,我需要在HAProxy上手动阻止某些IP地址。目前,我已无法记录他们。根据AWS文档,负载平衡器设置X-Forwarded-For请求头并填充客户端IP地址。
在尝试记录此标头(以及由此产生的客户机IP)时,我总是会得到带有HAProxy版本2.0.18和2.2.20的空字符串。所以我想,我把HAProxy配置错了。我的配置如下:
global
daemon
maxconn 256
log stdout format raw local0
defaults
mode http
option httplog
option dontlognull
timeout connect 15000ms
timeout client 150000ms
timeout server 150000ms
userlist global_auth
user someuser insecure-password somepass
frontend http-in
bind *:80
bind *:443 ssl crt /etc/certs/myapp-de.pem/cert_bundle_key.pem alpn h2,http/1.1
option httplog
option dontlognull
capture request header X-Forwarded-For len 500
capture request header x-forwarded-for len 500
log-format "Headers = --%hr--, --%hrl-- | Headers2: --%[capture.req.hdr(0)]--, --%[capture.req.hdr(1)]--"
log global
acl host_ssl_exception hdr(host) -i jobs.myapp.com
redirect scheme https code 301 if !{ ssl_fc } !host_ssl_exception
acl is_post method POST|OPTIONS
acl is_get method GET
default_backend myapp-web
backend myapp-web
mode http
compression algo gzip
compression type text/html text/plain text/css application/javascript application/json
server web1 myapp-web.myapp-${TRACK}.svc.cluster.local:80 maxconn 32 cookie check除一个后端外,所有其他都已删除。启用了HTTPS和HTTP2。capture似乎失败了,但目前我还不明白原因。
发布于 2022-02-06 12:03:43
将发送代理添加到后端myapp-web配置中的服务器配置行中,以便接收客户端的正确IP。
https://serverfault.com/questions/1092834
复制相似问题