Následující příklad nastavuje pravidla existující sady pravidel fáze ($RULESET_ID) do jediného origin pravidla, které přepisuje Host hlavičku příchozích požadavků a přeložený DNS záznam, a to pomocí Aktualizace sady pravidel zóny operace. Odpověď bude obsahovat úplnou definici aktualizovaného rulesetu.
Požadovaná oprávnění API tokenu
Alespoň jeden z následujících oprávnění tokenu je povinné:Response Compression WriteConfig Settings WriteDynamic URL Redirects WriteCache Settings WriteCustom Errors WriteOrigin WriteManaged headers WriteZone Transform Rules WriteMass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteHTTP DDoS Managed Ruleset WriteSanitize WriteTransform Rules WriteSelect Configuration WriteBot Management WriteZone WAF WriteAccount WAF WriteAccount Rulesets WriteLogs WriteLogs Write
Aktualizace sady pravidel zóny
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/$RULESET_ID" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"rules": [
{
"ref": "hr_app_overrides",
"expression": "starts_with(http.request.uri.path, \"/hr-app/\")",
"description": "Origin rule for the company HR application",
"action": "route",
"action_parameters": {
"host_header": "hr-server.example.com",
"origin": {
"host": "hr-server.example.com"
}
}
}
]
}'
{
"result": {
"id": "<RULESET_ID>",
"name": "Origin Rules ruleset",
"description": "Zone-level ruleset that will execute origin rules.",
"kind": "zone",
"version": "2",
"rules": [
{
"ref": "hr_app_overrides",
"id": "<RULE_ID>",
"version": "1",
"action": "route",
"action_parameters": {
"host_header": "hr-server.example.com",
"origin": {
"host": "hr-server.example.com"
}
},
"expression": "starts_with(http.request.uri.path, \"/hr-app/\")",
"description": "Origin rule for the company HR application",
"last_updated": "2022-06-03T14:42:04.219025Z",
"ref": "<RULE_REF>"
}
],
"last_updated": "2022-06-03T14:42:04.219025Z",
"phase": "http_request_origin"
},
"success": true,
"errors": [],
"messages": []
}
Použijte ref pole, abyste při použití Terraformu měli stabilní ID pravidel napříč aktualizacemi. Přidání tohoto pole zabrání tomu, aby Terraform při změnách pravidlo vytvářel znovu. Další informace najdete v Řešení potíží v dokumentaci Terraform.