

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 为应用程序负载均衡器启用 HTTP 标头修改
<a name="enable-header-modification"></a>

默认情况下，标头修改功能处于关闭状态，必须在每个侦听器上启用。有关更多信息，请参阅 [HTTP 标头修改](header-modification.md)。

------
#### [ Console ]

**启用标头修改**

1. 打开位于 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 的 Amazon EC2 控制台。

1. 在导航窗格中，选择**负载均衡器**。

1. 选择该应用程序负载均衡器。

1. 在**侦听器和规则**选项卡上，选择协议和端口，从而打开侦听器的详细信息页面。

1. 在 **Attributes**（属性）选项卡上，选择 **Edit**（编辑）。

   侦听器属性分为若干组。您需要选择要启用的功能。

1. [HTTPS 侦听器] **可修改 mTLS/TLS **的标头名称

   1. 展开**可修改的 mTLS/TLS 标题名称**。

   1. 启用要修改的请求标头并提供标头的名称。有关更多信息，请参阅 [重命名 mTLS/TLS 标题](header-modification.md#rename-header)。

1. **添加响应标头**

   1. 展开**添加响应标头**。

   1. 启用要添加的响应标头并提供标头的值。有关更多信息，请参阅 [添加响应标头](header-modification.md#insert-header)。

1. **ALB 服务器响应标头**

   1. 启用或禁用**服务器标头**。

1. 选择**保存更改**。

------
#### [ AWS CLI ]

**启用标头修改**  
使用 [modify-listener-attributes](https://docs.aws.amazon.com/cli/latest/reference/elbv2/modify-listener-attributes.html) 命令。要查看属性列表，请参阅[标头修改属性](#header-modification-attributes)。

```
aws elbv2 modify-listener-attributes \
    --listener-arn listener-arn \
    --attributes "Key=attribute-name,Value=attribute-value"
```

------
#### [ CloudFormation ]

**启用标头修改**  
更新[AWS::ElasticLoadBalancingV2::Listener](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-elasticloadbalancingv2-listener.html)资源以包含属性。要查看属性列表，请参阅[标头修改属性](#header-modification-attributes)。

```
Resources:
  myHTTPlistener:
  Type: 'AWS::ElasticLoadBalancingV2::Listener'
  Properties:
    LoadBalancerArn: !Ref myLoadBalancer
    Protocol: HTTP
    Port: 80
    DefaultActions:
      - Type: "forward"
        TargetGroupArn: !Ref myTargetGroup
    ListenerAttributes:
      - Key: "attribute-name"
        Value: "attribute-value"
```

------

## 标头修改属性
<a name="header-modification-attributes"></a>

以下为应用程序负载均衡器支持的标头修改属性。

`routing.http.request.x_amzn_mtls_clientcert_serial_number.header_name`  
修改 **X-Amzn-Mtls-Clientcert-Serial-Number** 的标头名称。

`routing.http.request.x_amzn_mtls_clientcert_issuer.header_name`  
修改 **X-Amzn-Mtls-Clientcert-Issuer** 的标头名称。

`routing.http.request.x_amzn_mtls_clientcert_subject.header_name`  
修改 **X-Amzn-Mtls-Clientcert-Subject** 的标头名称。

`routing.http.request.x_amzn_mtls_clientcert_validity.header_name`  
修改 **X-Amzn-Mtls-Clientcert-Validity** 的标头名称。

`routing.http.request.x_amzn_mtls_clientcert_leaf.header_name`  
修改 **X-Amzn-Mtls-Clientcert-Leaf** 的标头名称。

`routing.http.request.x_amzn_mtls_clientcert.header_name`  
修改 **X-Amzn-Mtls-Clientcert** 的标头名称。

`routing.http.request.x_amzn_tls_version.header_name`  
修改 **X-Amzn-Tls-Version** 的标头名称。

`routing.http.request.x_amzn_tls_cipher_suite.header_name`  
修改 **X-Amzn-Tls-Cipher-Suite** 的标头名称。

`routing.http.response.server.enabled`  
指示是否允许或移除 HTTP 响应服务器标头。

`routing.http.response.strict_transport_security.header_value`  
添加 **Strict-Transport-Security** 标头，以告知浏览器只能使用 HTTPS 访问该网站，并且将来任何使用 HTTP 访问该网站的尝试都应自动转换为 HTTPS。

`routing.http.response.access_control_allow_origin.header_value`  
添加 **Access-Control-Allow-Origin** 标头，以指定允许访问服务器的源。

`routing.http.response.access_control_allow_methods.header_value`  
添加 **Access-Control-Allow-Methods** 标头，以指定从其他源访问服务器时允许使用的 HTTP 方法。

`routing.http.response.access_control_allow_headers.header_value`  
添加 **Access-Control-Allow-Headers** 标头，以指定在跨源请求期间允许使用的标头。

`routing.http.response.access_control_allow_credentials.header_value`  
添加 **Access-Control-Allow-Credentials** 标头，以指示浏览器是否应在跨源请求中包含诸如 Cookie 或身份验证之类的凭证。

`routing.http.response.access_control_expose_headers.header_value`  
添加 **Access-Control-Expose-Headers** 标头，以指示浏览器可以向发出请求的客户端公开的标头。

`routing.http.response.access_control_max_age.header_value`  
添加 **Access-Control-Max-Age** 标头，以指定预检请求的结果可以缓存的时长（以秒为单位）。

`routing.http.response.content_security_policy.header_value`  
添加 **Content-Security-Policy** 标头，以指定浏览器为了帮助减少某些类型安全威胁的风险而强制实施的限制。

`routing.http.response.x_content_type_options.header_value`  
添加 **X-Content-Type-Options** 标头，以指示是否应遵循 **Content-Type** 标头中公开的 MIME 类型，而不应进行更改。

`routing.http.response.x_frame_options.header_value`  
添加 **X-Frame-Options** 标头，以指示是否允许浏览器在 **frame**、**iframe**、**embed** 或 **object** 中呈现页面。