Technology Encyclopedia Home >When the CDN origin site includes a load balancer, how do I configure the back-to-origin HTTP request header and how do I obtain the client's real IP address?

When the CDN origin site includes a load balancer, how do I configure the back-to-origin HTTP request header and how do I obtain the client's real IP address?

When configuring a CDN with a load balancer at the origin site, handling the back-to-origin HTTP request headers and obtaining the client's real IP address involves specific steps for accurate traffic management and security.

Configuring Back-to-Origin HTTP Request Headers:

To ensure that the CDN forwards requests to the appropriate backend servers through the load balancer, you need to configure custom headers. Typically, these headers include:

  • X-Forwarded-For (XFF): This header is used to identify the original client's IP address. When a request passes through multiple proxies or load balancers, each one appends its own IP address to this header.

    Example: X-Forwarded-For: client, proxy1, proxy2

  • X-Real-IP: Some systems use this header to directly pass the original client's IP address, bypassing any intermediate proxies.

    Example: X-Real-IP: client_ip_address

Obtaining the Client's Real IP Address:

To obtain the client's real IP address at the origin server, you can:

  1. Use the X-Forwarded-For Header: Parse this header to extract the first IP address, which represents the original client.

  2. Configure the CDN to Pass Real IPs: Ensure your CDN is configured to pass the real IP addresses through headers like X-Real-IP or X-Forwarded-For.

Example Configuration with Tencent Cloud CDN:

Tencent Cloud CDN allows you to configure these headers and settings:

  • Custom Headers: You can set custom headers in the CDN console to forward specific information to your origin server.

  • Real IP Configuration: Enable the "Enable Real IP" feature in the CDN settings. This feature allows you to specify which header (e.g., X-Forwarded-For or X-Real-IP) contains the client's real IP address.

By configuring these settings, you ensure that your load balancer and backend servers receive accurate information about the original clients, enhancing security, logging, and analytics capabilities.

For detailed configuration steps and more advanced features, refer to the Tencent Cloud CDN documentation or contact their support team.