AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-69710

kvz's questions

Martin Hope
kvz
Asked: 2016-07-10 01:20:51 +0800 CST

我可以使用 HAProxy 的新“捕获”功能将远程地址保存在 TCP 前端,并将其用作 HTTP 后端的“X-Forwarded-For”标头吗?

  • 6

使用 HAProxy 1.6 和一个聪明的 hack,我现在有一个 HAProxy tcp 模式前端,它检测浏览器是否支持 SNI,并基于此路由到强加密 SSL 终止后端,或者更弱的后端。这确保了 SSL 实验室的 A+ 评级,同时仍然允许除 IE6 之外的所有浏览器使用 SSL。

这是我的配置。它有一些模板变量应该是不言自明的,但与我的问题无关:

frontend https_incoming
 bind 0.0.0.0:443
 mode tcp
 option tcplog
 tcp-request inspect-delay 5s
 tcp-request content accept if { req.ssl_hello_type 1 }
 use_backend https_strong if { req.ssl_sni -m end .transloadit.com }
 default_backend https_weak

backend https_strong
 mode tcp
 option tcplog
 server https_strong 127.0.0.1:1665

frontend https_strong
 bind 127.0.0.1:1665 ssl crt ${DM_ROOT_DIR}/envs/ssl/haproxy-dh2048.pem no-sslv3 no-tls-tickets ciphers ${strongCiphers}
 mode http
 option httplog
 option httpclose
 option forwardfor if-none except 127.0.0.1
 http-response add-header Strict-Transport-Security max-age=31536000
 reqadd X-Forwarded-Proto:\ https
 reqadd FRONT_END_HTTPS:\ on
 use_backend http_incoming

backend https_weak
 mode tcp
 option tcplog
 server https_weak 127.0.0.1:1667

frontend https_weak
 bind 127.0.0.1:1667 ssl crt ${DM_ROOT_DIR}/envs/ssl/haproxy.pem no-sslv3 ciphers ${weakCiphers}
 mode http
 option httplog
 option httpclose
 option forwardfor if-none except 127.0.0.1
 http-response add-header Strict-Transport-Security max-age=31536000
 reqadd X-Forwarded-Proto:\ https
 reqadd FRONT_END_HTTPS:\ on
 use_backend http_incoming

问题:https_incoming前端知道客户端IP,但是由于它在mode tcp,它不能把这个信息保存在一个mode http X-Forwarded-Forheader中。option forwardfor在 TCP 模式下无效。

从另一个关于 serverfault 的问题 我已经发现我可以使用:

  • LVS
  • 代理协议

因此,据X-Forwarded-For我了解,在 LVS 的情况下,甚至不再需要标头:数据包被欺骗,因此源成为客户端 IP,而在代理的情况下:数据包被封装以携带客户端 IP。

这两个似乎都可以工作。然而,LVS 对我们来说似乎是一场可能有副作用的心脏手术,而 PROXY 的缺点是代理/应用程序上游/下游可能还不完全兼容。

我真的希望有更轻量级的东西,就在那时我发现了HAProxy 1.6 的新“捕获”功能,因为它提到:

您可以声明捕获槽,在其中存储数据并在会话期间随时使用它。

它继续显示以下示例:

defaults 
 mode http

frontend f_myapp
 bind :9001
 declare capture request len 32 # id=0 to store Host header
 declare capture request len 64 # id=1 to store User-Agent header
 http-request capture req.hdr(Host) id 0
 http-request capture req.hdr(User-Agent) id 1
 default_backend b_myapp

backend b_myapp
 http-response set-header Your-Host %[capture.req.hdr(0)]
 http-response set-header Your-User-Agent %[capture.req.hdr(1)]
 server s1 10.0.0.3:4444 check

在我看来,信息存储在前端,然后在后端使用,所以也许我可以在 TCP 模式下获取客户端 IP,保存它,然后在以后使用它,可能像这样:

http-response set-header X-Forwarded-For %[capture.req.hdr(0)]

我查看了捕获文档,似乎捕获更面向 http 模式标头,但后来我还看到一个邮件列表对话成功地演示了tcp-request capture.

我尝试了几件事,其中:

tcp-request capture req.hdr(RemoteAddr) id 0
# or
tcp-request content capture req.hdr(RemoteHost) id 0

但是正如您所看到的,我不知道语法应该是什么以及在哪个键下可以使用此信息,我也无法在(我认为)相关文档中找到它。

X-Forwarded-For问题:是否可以在 TCP 模式下捕获客户端 IP,然后再以 HTTP 模式将此信息写入标头?如果是这样,这将是什么语法?

ssl haproxy packet-capture
  • 2 个回答
  • 4484 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve