All Products
Search
Document Center

:Modify outgoing request headers

Last Updated:Sep 14, 2026

By default, Alibaba Cloud and DCDN 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.

Prerequisites

This feature is not enabled by default. To use this feature for a domain, you must first submit a ticket to enable it.

Background

An HTTP request header is part of an HTTP request message and is used to pass specific parameter information to a server.

When a or DCDN 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.

image

Usage notes

  • An outgoing request is an HTTP message that is sent from DCDN to an origin server. Modifying the outgoing request header configuration affects only HTTP messages that are sent from DCDN to an origin server. This configuration does not affect HTTP messages that are served directly from DCDN POPs to users.

  • You cannot modify outgoing request headers for a wildcard domain name.

  • If this feature is configured with conditions from the rules engine, the execution order is determined by the priority of the rule conditions, not the configuration order of the feature.

  • By default, Alibaba Cloud and DCDN include the following HTTP request headers in origin requests. No additional configuration is required.

    Origin HTTP header

    Description

    Example

    Ali-Cdn-Real-Ip

    The real IP address of the client connecting to a or DCDN POP.

    Ali-Cdn-Real-Ip:192.168.0.1

    X-Forwarded-For

    The IP addresses of the client and all intermediate or DCDN 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 or DCDN 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 or DCDN POPs that the client request passes through.

    Via:cn2546-10.l1, cache1.cn2546-10, l2cn2547-7.l2, cache1.l2cn2547-7

  • If you set the value of an outgoing request header to a variable, the variable is resolved to its actual value at runtime. The following variables are available.

    Parameter

    Origin HTTP header

    Description

    Example

    Ali-Cdn-Real-Port

    $http_Ali_Cdn_Real_Port

    Adds the client's real port to the origin request header to pass the port information to the origin server.

    Ali-Cdn-Real-Port:80

    Ali-Cdn-Real-Ip

    $http_Ali_Cdn_Real_Ip

    Adds the real IP address of the client to the origin request header to pass the client IP address information to the origin server.

    Ali-Cdn-Real-Ip:192.168.0.1

    x_forwarded_for

    $proxy_add_x_forwarded_for

    Appends the client IP address and the IP addresses of intermediate proxy servers to the X-Forwarded-For header to pass them to the origin server.

    X-Forwarded-For:192.168.0.1, 172.16.0.1

Procedure

  1. Log on to the DCDN console.

  2. In the left-side navigation pane, click Domain Names.

  3. On the Domain Names page, find the domain name that you want to manage and click Configure in the Actions column.

  4. In the domain's navigation pane, click Origin Fetch.

  5. Click the Modify Outgoing Request Header tab.

  6. On the Modify Outgoing Request Header tab, click Add.

  7. Configure the parameters for the header modification.

    Important

    If multiple conflicting operations target the same origin request header, only the one with the highest priority is executed. The priority order from highest to lowest is: Replace > Add > Change/Delete. For example, if you configure both an Add and a Delete operation for the same header, only the Add operation is executed.

    Add request header

    Parameter

    Example

    Description

    Operation

    Add

    Adds the specified header to origin HTTP requests.

    Request header

    Custom header

    Select a preset request header or select Custom header.

    Request header name

    x-code

    The name of the custom request header. In this example, x-code.

    Header value

    key1

    You can specify one or more values. Separate multiple values with a comma (,).

    key1, key2

    Allow duplicates

    Yes

    • Yes: Allows adding duplicate request headers. For example, x-code:key1 and x-code:key2.

    • No: If you add a header with the same name as an existing header, the new value overwrites the old one. For example, if you first add x-code:key1 and then add x-code:key2, the final header is x-code:key2.

    Delete request header

    Parameter

    Example

    Description

    Operation

    Delete

    Deletes all header values that match the specified header name, including any duplicates.

    Request header

    Custom header

    Select a preset request header or select Custom header.

    Request header name

    x-code

    The name of the custom request header. In this example, x-code.

    Change request header

    Parameter

    Example

    Description

    Operation

    Change

    Changes the value of a header. This operation is not allowed if multiple headers with the same name exist.

    Request header

    Custom header

    Select a preset request header or select Custom header.

    Request header name

    x-code

    The name of the custom request header. In this example, x-code.

    Change to

    key1, key3

    You can specify one or more values. Separate multiple values with a comma (,).

    Replace request header

    Parameter

    Example

    Description

    Operation

    Replace

    Replaces part of a header's value by using a regular expression. This operation is not allowed if multiple headers with the same name exist.

    Request header

    Custom header

    Select a preset request header or select Custom header.

    Request header name

    x-code

    The name of the custom request header. In this example, x-code.

    Find

    key

    A regular expression to find the value to be replaced.

    Replace with

    abc

    The string to replace the matched text. Regular expression back-references are supported.

    Match

    Match All

    • Match All: Replaces all matched values. For example, if you replace "key" with "abc" in x-code:key1,key2,key3, the result is x-code:abc1,abc2,abc3.

    • Match the First Only: Replaces only the first matched value. For example, if you replace "key" with "abc" in x-code:key1,key2,key3, the result is x-code:abc1,key2,key3.

  8. Click OK.

Related API

BatchSetDcdnDomainConfigs