By default, Alibaba Cloud CDN and support forwarding request headers, such as those that contain the client IP address. You can also configure custom headers. To rewrite HTTP headers in origin requests, you can modify outgoing request headers. This feature allows you to add, delete, change, or replace origin HTTP request headers to meet your business requirements.
Background information
An HTTP request header is part of an HTTP request message and is used to pass specific parameter information to a server.
When a CDN or point of presence (POP) sends a request to an origin server to retrieve resources, the origin server can access the information in the origin request header. You can use this feature to rewrite HTTP header information in origin requests and send specific parameters to your origin server.
To learn how an origin server retrieves the real client IP address from the X-Forwarded-For header in an origin request, see Obtain the real IP address of a client.
Notes
An outgoing request is an HTTP message that is sent from CDN to an origin server. Modifying the outgoing request header configuration affects only HTTP messages that are sent from CDN to an origin server. This configuration does not affect HTTP messages that are served directly from CDN POPs to users.
You cannot modify outgoing request headers for a wildcard domain name.
-
ApsaraVideo VOD forwards the following back-to-origin HTTP request headers by default. No additional configuration is required.
Origin HTTP header
Description
Example
Ali-Cdn-Real-Ip
The real IP address of the client connecting to a CDN or POP.
Ali-Cdn-Real-Ip:192.168.0.1
X-Forwarded-For
The IP addresses of the client and all intermediate CDN or POPs in the path of the origin request.
X-Forwarded-For:192.168.0.1, 172.16.0.1
X-Client-Scheme
The application-layer protocol, such as HTTP or HTTPS, that a client uses to send a request to a CDN or POP.
X-Client-Scheme:http
Host
The domain name of the origin website that is accessed by the origin request.
Host:example.com
Via
The names of all CDN or POPs that the client request passes through.
Via:cn2546-10.l1, cache1.cn2546-10, l2cn2547-7.l2, cache1.l2cn2547-7
Procedure
-
Log on to the ApsaraVideo VOD console.
In the left-side navigation pane, choose Configuration Management > CDN Configuration > Domain Names.
-
Find the desired domain name and click Configure in the Actions column.
-
In the domain's left-side navigation pane, click Back-to-Origin.
-
Click the Back-to-origin HTTP Request Header tab.
-
Click Add and configure the header settings.
ImportantIf you configure different operations for the same origin request header, a conflict occurs, and the highest-priority operation is executed. The priority order is: Replace > Add > Change and Delete.
Add header
Delete header
Change header
Replace header
-
Click OK to complete the configuration.
Examples
Example 1
Scenario: Add the X-Forwarded-For header to back-to-origin requests to pass the client IP and intermediate proxy server IPs to the origin server.
ApsaraVideo VOD includes the X-Forwarded-For header in back-to-origin requests by default. No configuration is needed unless you want to change the header name.
Configuration:
-
Custom Header Name: X-Forwarded-For
-
Header Value: $proxy_add_x_forwarded_for
In the Back-to-origin HTTP Request Header dialog box, set Header Operation to Add, Custom Request Header Parameter to Custom back-to-origin request header, and Allow Duplicates to Do not allow. Then, click OK.
-
Custom request header name: X-Forwarded-For.
-
Request header value: $proxy_add_x_forwarded_for.
Example 2
Scenario: Add a header to back-to-origin requests to pass the real client IP address to the origin server.
ApsaraVideo VOD includes the Ali-Cdn-Real-Ip header in back-to-origin requests by default. This header contains the real client IP address. No configuration is needed unless you want to change the header name.
Configuration:
-
Custom Header Name: X-Real-IP
-
Header Value: $http_Ali_Cdn_Real_Ip
Set Header Operation to Add, Custom Request Header Parameter to Custom back-to-origin request header, and Allow Duplicates to Do not allow. Then, click OK.
Example 3
Scenario: Add a header to back-to-origin requests to pass the client's real port to the origin server.
ApsaraVideo VOD includes the Ali-Cdn-Real-Port header in back-to-origin requests by default. This header contains the real client port. No configuration is needed unless you want to change the header name.
Configuration:
-
Custom Header Name: X-Real-Port
-
Header Value: $http_Ali_Cdn_Real_Port
Set Header Operation to Add, Custom Request Header Parameter to Custom back-to-origin request header, and Allow Duplicates to Do not allow. Then, click OK.