All Products
Search
Document Center

Server Load Balancer:HTTP headers

Last Updated:Jan 10, 2025

This topic describes the non-standard HTTP headers supported by Application Load Balancer (ALB) and how to add a non-standard HTTP header to a listener. You can customize the non-standard headers to implement features.

Non-standard HTTP headers supported by ALB

An HTTP header is a part of an HTTP request or response and carries additional information about the request or response. You can configure non-standard HTTP headers on a browser or a web server based on your business requirements. The following table describes the non-standard HTTP headers supported by ALB.

Header

Description

Listener protocol

X-Forwarded-For

Listeners can use the X-Forwarded-For header to obtain client IP addresses.

  • If you select Add X-Forwarded-For to preserve client IP addresses, ALB can add an X-Forwarded-For header to or remove the X-Forwarded-For header from the request before forwarding the request to a backend server.

    • Add (default)

      If you choose Add, ALB adds the IP address of the last hop to the X-Forwarded-For header in the request before forwarding the request to a backend server. If the request does not contain the X-Forwarded-For header, ALB creates an X-Forwarded-For header whose value is the IP address of the last hop and adds the header to the request. The X-Forwarded-For header in the request may contain multiple IP addresses which are separated by commas (,).

    • Remove

      If you choose Remove, ALB removes the X-Forwarded-For header from the request before forwarding the request to a backend server.

  • If you do not select Add X-Forwarded-For to preserve client IP addresses, ALB does nothing about the X-Forwarded-For header in the request before forwarding the request to a backend server.

Format:

X-Forwarded-For: <client-ip-address>, <proxy1>, <proxy2>, …

The X-Forwarded-For header in the request that is received by the backend server is described as follows. In this example, the IP address of the last hop is 127.0.0.1.

Request description

Sample request

Select Add X-Forwarded-For to preserve client IP addresses

Not select Add X-Forwarded-For to preserve client IP addresses

Add

Remove

The request received by ALB does not contain the X-Forwarded-For header.

GET /index.html HTTP/1.1

Host: example.com

X-Forwarded-For: 127.0.0.1

The X-Forwarded-For header does not exist.

The X-Forwarded-For header does not exist.

The request received by ALB contains the X-Forwarded-For header and a client IP address.

GET /index.html HTTP/1.1

Host: example.com

X-Forwarded-For: 127.0.0.2

X-Forwarded-For: 127.0.0.2, 127.0.0.1

The X-Forwarded-For header does not exist.

X-Forwarded-For: 127.0.0.2

The request received by ALB contains the X-Forwarded-For header and multiple client IP addresses.

GET /index.html HTTP/1.1

Host: example.com

X-Forwarded-For: 127.0.0.2, 127.0.0.3

X-Forwarded-For: 127.0.0.2, 127.0.0.3, 127.0.0.1

The X-Forwarded-For header does not exist.

X-Forwarded-For: 127.0.0.2, 127.0.0.3

For more information about how to enable ALB to preserve client IP addresses, see Enable ALB to preserve client IP addresses.

  • HTTP

  • HTTPS

SLB-ID

Listeners can use the SLB-ID to obtain ALB instance IDs.

  • HTTP

  • HTTPS

  • QUIC

X-Forwarded-Proto

Listeners can use the X-Forwarded-Proto header to obtain the protocol between the client and the listener. This way, applications can identify the protocol in the X-Forwarded-Proto header and perform redirects.

Format:

X-Forwarded-Proto: <originatingProtocol>
  • HTTP

  • HTTPS

  • QUIC

X-Forwarded-Port

Listeners can use the X-Forwarded-Port header to obtain the port over which the client and the listener communicate.

Format:

X-Forwarded-Port: <port>
  • HTTP

  • HTTPS

  • QUIC

X-Forwarded-Host

Listeners can use the X-Forwarded-Host header to obtain the domain name of the client.

Format:

X-Forwarded-Host: <host>
  • HTTP

  • HTTPS

  • QUIC

X-Forwarded-Client-srcport

Listeners can use the X-Forwarded-Client-srcport header to obtain the client port.

Format:

X-Forwarded-Client-srcport: <port>
  • HTTP

  • HTTPS

X-Forwarded-Clientcert-subjectdn

Listeners can use the X-Forwarded-Clientcert-subjectdn header to obtain the information about the client certificate owner.

To use this header, you must specify a key for the custom header.

HTTPS

X-Forwarded-Clientcert-issuerdn

Listeners can use the X-Forwarded-Clientcert-issuerdn header to obtain the information about the client certificate authority.

To use this header, you must specify a key for the custom header.

HTTPS

X-Forwarded-Clientcert-fingerprint

Listeners can use the X-Forwarded-Clientcert-fingerprint header to obtain the fingerprint value of the client certificate.

To use this header, you must specify a key for the custom header.

HTTPS

X-Forwarded-Clientcert-clientverify

Listeners can use the X-Forwarded-Clientcert-clientverify header to obtain the authentication result of the client certificate.

To use this header, you must specify a key for the custom header.

HTTPS

Note
  • We recommend that you configure your backend servers to follow the HTTP standard – be case-insensitive when processing the request headers.

    • The X-Forwarded-For header that is created and added to the request by ALB always starts with an uppercase "X."

    • Except for X-Forwarded-For, for the headers mentioned above, ALB processes them following the rules described above. For other headers, ALB keeps them in their original form in the request.

  • You cannot specify the custom header keys of X-Forwarded-Clientcert-subjectdn, X-Forwarded-Clientcert-issuerdn, X-Forwarded-Clientcert-fingerprint, and X-Forwarded-Clientcert-clientverify as follows:

    slb-id, slb-ip, x-forwarded-for, x-forwarded-proto, x-forwarded-eip, x-forwarded-port, x-forwarded-client-srcport, x-forwarded-host, connection, upgrade, content-length, transfer-encoding, keep-alive, te, host, cookie, remoteip, and authority

Add HTTP headers in the console

Add an HTTP header when you create a listener

  1. Log on to the ALB console.

  2. In the top navigation bar, select the region in which the ALB instance is deployed.

  3. Use one of the following methods to open the listener configuration wizard:

    • On the Instances page, find the ALB instance that you want to manage and click Create Listener in the Actions column.

    • On the Instances page, click the ID of the ALB instance that you want to manage. On the Listener tab, click Create Listener.

  4. In the Configure Listener step, configure the following parameters and click Next.

    Parameter

    Description

    Listener Protocol

    Select a listener protocol.

    Advanced Settings

    You can click Modify to configure the advanced settings.

    Custom HTTP Header

    Select the HTTP headers that you want to add.

    Note

    For more information about other parameters, see the following topics:

  5. Complete the configurations as prompted.

Add an HTTP header to an existing listener

  1. Log on to the ALB console.

  2. In the top navigation bar, select the region in which the ALB instance is deployed.

  3. On the Instances page, click the ID of the ALB instance that you want to manage.

  4. Click the Listener tab, find the listener that you want to manage and choose 更多Modify Listener in the Actions column.

  5. In the Modify Listener dialog box, click Modify on the right side of Advanced Settings.

  6. In the Custom HTTP Header section, add or remove HTTP headers and click Save.

Add HTTP headers by making API calls

You can specify the headers that you want to add when you call the API to create a listener. When you call the API to add, keep, or remove headers for an existing listener.

  • To add an HTTP header when you create a listener, set the XForwardedForConfig parameter when you call the CreateListener operation.

  • To manage the HTTP headers of an existing listener, modify the XForwardedForConfig parameter when you call the UpdateListenerAttribute operation.

References

Console operations

API references

  • CreateListener: Creates an HTTP, HTTPS, or QUIC listener. You can set the XForwardedForConfig parameter in the request to add HTTP headers.

  • UpdateListenerAttribute: Modifies the configurations of a listener. You can modify the XForwardedForConfig parameter in the request to add, keep, or removes HTTP headers.