INTEGRITY Dokumentace

Změna cílového portu

Následující origin rule přepisuje cílový port na 8081 pro všechny požadavky, u kterých cesta URI začíná na /team/calendar/.

Text v Expression Editor:

starts_with(http.request.uri.path, "/team/calendar/")

Hodnota po Cílový port > Přepsat na:

8081

Následující příklad nastavuje pravidla existující sady pravidel fáze ($RULESET_ID) do jediného origin pravidla, které přepisuje port příchozích požadavků 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 Write
  • Config Settings Write
  • Dynamic URL Redirects Write
  • Cache Settings Write
  • Custom Errors Write
  • Origin Write
  • Managed headers Write
  • Zone Transform Rules Write
  • Mass URL Redirects Write
  • Magic Firewall Write
  • L4 DDoS Managed Ruleset Write
  • HTTP DDoS Managed Ruleset Write
  • Sanitize Write
  • Transform Rules Write
  • Select Configuration Write
  • Bot Management Write
  • Zone WAF Write
  • Account WAF Write
  • Account Rulesets Write
  • Logs Write
  • Logs 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": "calendar_app_change_port",
						"expression": "starts_with(http.request.uri.path, \"/team/calendar/\")",
						"description": "Origin rule for the team calendar application",
						"action": "route",
						"action_parameters": {
								"origin": {
										"port": 8081
								}
						}
				}
		]
	}'
{
	"result": {
		"id": "<RULESET_ID>",
		"name": "Origin Rules ruleset",
		"description": "Zone-level ruleset that will execute origin rules.",
		"kind": "zone",
		"version": "2",
		"rules": [
			{
				"ref": "calendar_app_change_port",
				"id": "<RULE_ID>",
				"version": "1",
				"action": "route",
				"action_parameters": {
					"origin": {
						"port": 8081
					}
				},
				"expression": "starts_with(http.request.uri.path, \"/team/calendar/\")",
				"description": "Origin rule for the team calendar 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.