跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

使用 Terraform 定义单条源站规则

Create an origin rule using Terraform to override the Host header, the resolved hostname, and the destination port of API requests.

最后更新 查看 MarkdownAgent 设置

以下示例使用 Terraform 为一个 zone 定义单条源站规则。该规则会覆盖 API 请求的 Host 标头、解析后的主机名和目标端口。

# Change origin for API requests
resource "cloudflare_ruleset" "http_origin_example" {
  zone_id     = "<ZONE_ID>"
  name        = "Change origin"
  description = ""
  kind        = "zone"
  phase       = "http_request_origin"

  rules {
	  ref         = "change_api_origin"
    description = "Change origin of API requests"
    expression  = "(http.request.uri.path matches \"^/api/\")"
    action      = "route"
    action_parameters {
      host_header = "example.net"
      origin {
        host = "example.net"
        port = 8000
      }
    }
  }
}

使用 Terraform 时,通过 ref 字段使规则 ID 在更新之间保持稳定。添加此字段可防止 Terraform 在发生变更时重新创建规则。更多信息请参阅 Terraform 文档中的故障排除。

其他资源

有关将 Terraform 与 Cloudflare 配合使用的其他指南,请参阅以下资源:

这篇文档对您有帮助吗?