首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何访问AWS负载均衡器后面的HAProxy上的X转发标头

如何访问AWS负载均衡器后面的HAProxy上的X转发标头
EN

Server Fault用户
提问于 2022-02-06 10:56:47
回答 1查看 2.3K关注 0票数 0

在运行在HAProxy上的K8S实例上,我需要在HAProxy上手动阻止某些IP地址。目前,我已无法记录他们。根据AWS文档,负载平衡器设置X-Forwarded-For请求头并填充客户端IP地址。

在尝试记录此标头(以及由此产生的客户机IP)时,我总是会得到带有HAProxy版本2.0.18和2.2.20的空字符串。所以我想,我把HAProxy配置错了。我的配置如下:

代码语言:javascript
运行
复制
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似乎失败了,但目前我还不明白原因。

EN

回答 1

Server Fault用户

发布于 2022-02-06 12:03:43

将发送代理添加到后端myapp-web配置中的服务器配置行中,以便接收客户端的正确IP。

票数 -1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1092834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档