为应用程序负载均衡器启用 HTTP 标头修改 - Elastic Load Balancing
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

为应用程序负载均衡器启用 HTTP 标头修改

默认情况下,标头修改功能处于关闭状态,必须在每个侦听器上启用。有关更多信息,请参阅 HTTP 标头修改

Console
启用标头修改
  1. 打开 Amazon EC2 控制台,网址为https://console.aws.amazon.com/ec2/

  2. 在导航窗格中,选择负载均衡器

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

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

  5. Attributes(属性)选项卡上,选择 Edit(编辑)。

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

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

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

    2. 启用要修改的请求标头并提供标头的名称。有关更多信息,请参阅 重命名 mTLS/TLS 标题

  7. 添加响应标头

    1. 展开添加响应标头

    2. 启用要添加的响应标头并提供标头的值。有关更多信息,请参阅 添加响应标头

  8. ALB 服务器响应标头

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

  9. 选择保存更改

Amazon CLI
启用标头修改

使用 modify-listener-attributes 命令。要查看属性列表,请参阅标头修改属性

aws elbv2 modify-listener-attributes \ --listener-arn listener-arn \ --attributes "Key=attribute-name,Value=attribute-value"
CloudFormation
启用标头修改

更新AWS::ElasticLoadBalancingV2::Listener资源以包含属性。要查看属性列表,请参阅标头修改属性

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"

标头修改属性

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

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 标头,以指示是否允许浏览器在 frameiframeembedobject 中呈现页面。