【问题标题】:Does cloudflare cf-connecting-ip affect http header?cloudflare cf-connecting-ip 会影响 http 标头吗?
【发布时间】:2021-04-08 00:53:18
【问题描述】:

在使用 cloudflare 服务之前,我有几个问题。

  1. web 服务器使用cf-connecting-ip,x-forwarded-for 等和 web 不使用这些东西之间的 http 请求头有什么区别吗?

  2. 客户端能否/如何知道 Web 服务器使用 cf-connecting-ipx-forwarded-for 等?

【问题讨论】:

    标签: cloudflare x-forwarded-for


    【解决方案1】:

    这些请求标头特定于 Web 代理,并在 Cloudflare 收到请求后附加到您的源站时。用户看不到它,除非您的网络服务器出于某种原因将其发回。

    x-forwarded-for: https://en.wikipedia.org/wiki/X-Forwarded-For 代理服务器使用它来告诉源站在用户和源站之间中继请求所涉及的任何 HTTP 服务器。您可能会在此标头中看到 1 组或多组 IP 地址。

    cf-connecting-ip: 将连接到 Cloudflare 的用户的 IP 中继到源网络服务器

    发件人:https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers-

    CF-Connecting-IP 提供客户端(访问者)IP地址(连接 到 Cloudflare)到源 Web 服务器。 cf-connecting-ip 包含一个 特殊 Cloudflare IP 2a06:98c0:3600:0:0:0:0:103 请求时 源自 Cloudflare Workers 子请求,而不是 访问者的真实 IP。

    例子:

    CF-连接-IP:203.0.113.1

    X-Forwarded-For 维护代理服务器和原始访问者 IP 地址。如果没有现有的 X-Forwarded-For 标头 发送到 Cloudflare 的请求,X-Forwarded-For 具有与 CF-Connecting-IP 标头:

    例子:

    X-Forwarded-For: 203.0.113.1 如果 X-Forwarded-For 标头已经存在 出现在对 Cloudflare 的请求中,Cloudflare 会附加 IP 标头的 HTTP 代理地址:

    例子:

    X-Forwarded-For: 203.0.113.1,198.51.100.101,198.51.100.102 在 上面的例子,203.0.113.1 是原始访问者 IP 地址, 198.51.100.101 和 198.51.100.102 是通过 X-Forwarded-For 标头提供给 Cloudflare 的代理服务器 IP 地址。

    因此,为了获得建议,请查看您的应用程序,看看它是否取决于用户的 IP,如果是,您将需要修改您的网络服务器配置以中继正确的 IP。

    要在您的源网络服务器上恢复原始访问者 IP 地址, Cloudflare 建议您的日志或应用程序查看 CF-Connecting-IP 或 True-Client-IP 而不是 X-Forwarded-For,因为 CF-Connecting-IP 和 True-Client-IP 格式一致 仅包含一个 IP。

    【讨论】:

      猜你喜欢
      • 2020-07-29
      • 2011-04-15
      • 2015-10-16
      • 1970-01-01
      • 2010-10-22
      • 2020-06-03
      • 1970-01-01
      • 2012-04-07
      • 2014-10-16
      相关资源
      最近更新 更多