在采用代理和负载均衡器的现代网络架构中,客户端 IP 识别流程非常具有挑战性,因为这些中间方可能会模糊真实的来源 IP 地址。
为克服这一挑战,Apigee 支持一种环境级设置,用于指定如何从 X-Forwarded-For (XFF) 标头解析客户端 IP 地址,从而识别标头中与您的网络拓扑和安全要求匹配的 IP 地址的索引。使用此设置可让您清楚了解、保持一致并控制如何确定环境中所有请求的客户端 IP 地址,并确保在环境中的 Advanced API Security、流变量和分析变量之间保持一致的客户端 IP 地址识别。
如果未按本页面所述配置环境级客户端 IP 解析,则客户端 IP 地址变量会使用默认客户端 IP 地址解析行为进行填充。
默认客户端 IP 地址解析
如果未在环境级配置客户端 IP 解析,则 ax_resolved_client_ip 维度的默认值将如 Analytics 维度所述进行计算。
如果为环境配置了客户端 IP 解析,则流和 Analytics 变量会根据客户端 IP 解析配置进行设置。请参阅为环境设置客户端 IP 解析。
何时为环境设置客户端 IP 解析
虽然无需设置客户端 IP 解析,但如果默认客户端 IP 地址解析无法满足您的需求,并且您希望替换它以提供指定的客户端 IP 地址解析,以便进行 Analytics、Advanced API Security 或执行任何其他需要有关客户端 IP 地址的一致可靠信息的功能,则可能需要设置客户端 IP 解析。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThis page provides guidance on how to accurately identify the client IP address in API requests within Apigee and Apigee hybrid, which is crucial for features like Analytics and Advanced API Security.\u003c/p\u003e\n"],["\u003cp\u003eApigee supports configuring environment-level client IP resolution using the X-Forwarded-For (XFF) header to handle challenges posed by proxies and load balancers that may obscure the true originating IP address.\u003c/p\u003e\n"],["\u003cp\u003eThe client IP resolution configuration uses an \u003ccode\u003eipHeaderName\u003c/code\u003e (currently only X-Forwarded-For) and an \u003ccode\u003eipHeaderIndex\u003c/code\u003e to specify how to extract the client IP from the header, allowing selection from either the left or right side of the address list.\u003c/p\u003e\n"],["\u003cp\u003eIf the client IP resolution is not configured at the environment level, the default client IP address resolution method is applied, but it can be overridden to provide a more precise identification method.\u003c/p\u003e\n"],["\u003cp\u003eAfter setting a client IP resolution, changes can take up to 5 minutes to be applied, updates should not be frequent, and the config can be seen but only set using the API.\u003c/p\u003e\n"]]],[],null,["# Client IP resolution\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nAccurately identifying the client IP address on API requests is important for some functionality\nwithin Apigee, including\n[Analytics](/apigee/docs/api-platform/analytics/analytics-services-overview) and\n[Advanced API Security](/apigee/docs/api-security)\nfeatures such as abuse detection and security actions.\n\nThe client IP identification process is challenging in modern network architectures that employ proxies and load balancers, as\nthese intermediaries can obscure the true originating IP address.\n\nTo overcome this challenge, Apigee supports an environment-level setting specifying\nhow to resolve the client IP address from the X-Forwarded-For (XFF) header, identifying\nthe index in the header that matches the IP address for your network topology and security\nrequirements. Using this setting provides visibility, consistency, and control over how client IP addresses\nare determined for all requests in the environment and results in consistent client IP address identification\nacross Advanced API Security, flow variables, and analytics variables in the environment.\n\nIf the environment-level client IP resolution is not configured as described on this page, the\nclient IP address variables are populated using the\n[default client IP address resolution](#default-client-ip-address-resolution) behavior.\n\nDefault client IP address resolution\n------------------------------------\n\nIf client IP resolution is not configured at the environment level, the default value of the\n`ax_resolved_client_ip` dimension is calculated as described in\n[Analytics dimensions](/apigee/docs/api-platform/analytics/analytics-reference#dimensions).\n\nIf client IP resolution *is* configured for an environment, the flow and Analytics\nvariables are set from the client IP resolution configuration. See\n[Set the client IP resolution for an environment](#set-client-ip-resolution-for-an-environment).\n\nWhen to set the client IP resolution for an environment\n-------------------------------------------------------\n\nAlthough it's not required to set client IP resolution, you might want to if the\n[default client IP address resolution](#default-client-ip-address-resolution) does not\nmeet your needs and you want to override it to provide a specified client IP address\nresolution for Analytics, Advanced API Security, or performing any other function that requires\nconsistent and reliable information on client IP addresses.\n\nUnderstand the client IP resolution configuration syntax\n--------------------------------------------------------\n\nThe client IP resolution setting has this format: \n\n```\n\"clientIpResolutionConfig\": {\n \"headerIndexAlgorithm\": {\n \"ipHeaderName\" : \"X-Forwarded-For\",\n \"ipHeaderIndex\": 2\n }\n}\n```\nwhere\n\n- `ipHeaderName` is the header to use for the client IP. At this time, `X-Forwarded-For` is the supported header value.\n- `ipHeaderIndex` is the index value within the `ipHeaderName`. \n\n A positive number selects an address starting from the left (the first address added to the header), where the first position on the left is `0` and increases by one for each subsequent address (e.g. `0, 1, 2`). For example, if the list is `192.0.2.1, 192.0.2.2, 192.0.2.3`, an index of `1` resolves to `192.0.2.2`. \n\n A negative number selects an address starting from the right (the last address added to the header) where the first position on the right is `-1` and decrements by one for each subsequent address (e.g. `-3, -2, -1`). For example, if the list is `192.0.2.1, 192.0.2.2, 192.0.2.3, 192.0.2.4`, an index of `-1` resolves to `192.0.2.4` and the index `-2` resolves to `192.0.2.3`.\n\nSee the [organizations.environment API](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments#Environment)\nfor additional information about this setting.\n\nView client IP resolution configurations\n----------------------------------------\n\nYou can view the current client IP resolution configuration for an environment using either\nthe Apigee UI or Management APIs.\n\n### View the client IP resolution configuration using the UI\n\nTo view the client IP resolution configuration:\n\n1. In the Google Cloud console, go to the **Management \\\u003e Environments** page.\n\n [Go to Environments](https://console.cloud.google.com/apigee/environments)\n2. Select the environment, and see **Client IP configuration** in\n the **About** tab.\n\n### View the client IP resolution configuration using the API\n\nTo use the Apigee Management APIs to view the client IP resolution configuration, send a request to the\n[organizations.environments.get API](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/get).\n\nSet client IP resolution for an environment\n-------------------------------------------\n\nAfter setting the client IP resolution configuration for an environment, the [`client.resolved.ip`](/apigee/docs/api-platform/reference/variables-reference#client)\nflow variable populates using the specified algorithm. So does the\n[`Resolved Client IP` Analytics dimension](/apigee/docs/api-platform/analytics/analytics-reference#dimensions).\n\nOnce you've set the client IP resolution configuration for an environment, the changes\nmight impact existing Advanced API Security configurations for security action rules. Review and, if necessary, regenerate\nexisting rules to use the new variables and settings.\n\nKeep these implications in mind when selecting the index for Client IP resolution:\n\n- Apigee to Apigee calls are not handled as a special case. Take care to note and skip the number of IPs accordingly.\n- Since the X-Forwarded-For header can be spoofed, it's better to use the right index based on the number of expected hops between the client and the Apigee load balancer. A malicious user can send a pre-filled X-Forwarded-For header. While the first IP in the XFF is closest to the actual client IP, the last IP in the XFF is most trustworthy, given the load balancer knows the TCP client which is connected to it.\n\nTo set client IP resolution on an environment, use one of the Apigee API Management APIs to set\nthe client IP resolution for the environment in the `client_ip_resolution_config`.\nUse\n[organizations.environments.create](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/create)\nfor new environments. Use\n[updateEnvironment](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/updateEnvironment) or\n[modifyEnvironment](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/modifyEnvironment)\nfor existing environments.\n\nTest the client IP address resolution\n-------------------------------------\n\nAfter saving a new client IP configuration, you can test it by following these instructions:\n\n1. Wait at least 5 minutes after saving a new configuration setting.\n2. Start a [debug session](/apigee/docs/api-platform/debug/trace). Enable the setting to **Show all FlowInfos**.\n3. Check the **FlowInfo** just before **Proxy Request Flow Started**. You should see the configured client IP address captured in that section.\n\nLook for these variables in the FlowInfo:\n\n- `client_ip_resolution.resolved.ip`: The resolved client IP address.\n- `client_ip_resolution.used.fallback`: Boolean. This value is `false` unless Apigee fell back to the default client IP resolution due to an inability to use a configured client IP resolution. For example, if the configured resolution specifies an index which doesn't exist in the header.\n- `client_ip_resolution.algorithm`: The algorithm used to determine the client IP address. If configured, this is `\"HeaderIndexAlgorithm{IpHeaderName:`\u003cvar translate=\"no\"\u003eheader_name\u003c/var\u003e`, IpHeaderIndex: `\u003cvar translate=\"no\"\u003e$header_index\u003c/var\u003e`}\"`. Otherwise, this shows `default`.\n\nLimitations\n-----------\n\nThese limitations apply to environment-level client IP resolution:\n\n- Updates to client IP resolution configurations can take up to 5 minutes to be effective.\n- Avoid frequent (for example, every 5 minutes) changes to the client IP resolution configuration, as this could cause performance degradation.\n- Setting the client IP resolution configuration for an environment in Apigee hybrid is available with hybrid versions 1.14.0 and later.\n- The configuration can be viewed via the Apigee Console or API but can be set only via the API.\n- Even in the absence of malicious users, the X-Forwarded-For list relies on each proxy to add the right information to the list. That complete list is outside Apigee's oversight and control, so setting the client IP resolution configuration does not guarantee identification of the correct request IP address."]]