← Cloudflare Rules / rules / compression-rules / examples
Povolení komprese Zstandard pro výchozí typy obsahu
Následující ukázkové pravidlo zapne kompresi Zstandard pro typy obsahu odpovědi, kde Cloudflare ve výchozím nastavení používá kompresi. Pokud klient nepodporuje kompresi Zstandard, jako záložní řešení použije kompresi Brotli nebo Gzip.
Když příchozí požadavky odpovídají
- Vlastní filtrovací výraz:
- Typ média is in
text/html, text/richtext, text/plain, text/css, text/x-script, text/x-component, text/x-java-source, text/x-markdown, application/javascript, application/x-javascript, text/javascript, text/js, image/x-icon, image/vnd.microsoft.icon, application/x-perl, application/x-httpd-cgi, text/xml, application/xml, application/rss+xml, application/vnd.api+json, application/x-protobuf, application/json, multipart/bag, multipart/mixed, application/xhtml+xml, font/ttf, font/otf, font/x-woff, image/svg+xml, application/vnd.ms-fontobject, application/ttf, application/x-ttf, application/otf, application/x-otf, application/truetype, application/opentype, application/x-opentype, application/font-woff, application/eot, application/font, application/font-sfnt, application/wasm, application/javascript-binast, application/manifest+json, application/ld+json, application/graphql+json, application/geo+json
Poté
- Možnosti komprese: Custom
- Definujte vlastní pořadí typů komprese:
Zstandard, Brotli, Gzip
Následující příklad nastavuje pravidla existujícího vstupní sada pravidel (s ID {ruleset_id}) pro http_response_compression fázi na jedno pravidlo komprese pomocí Aktualizace sady pravidel zóny operace:
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": "use_zstd_compression",
"expression": "(http.response.content_type.media_type in {\"text/html\" \"text/richtext\" \"text/plain\" \"text/css\" \"text/x-script\" \"text/x-component\" \"text/x-java-source\" \"text/x-markdown\" \"application/javascript\" \"application/x-javascript\" \"text/javascript\" \"text/js\" \"image/x-icon\" \"image/vnd.microsoft.icon\" \"application/x-perl\" \"application/x-httpd-cgi\" \"text/xml\" \"application/xml\" \"application/rss+xml\" \"application/vnd.api+json\" \"application/x-protobuf\" \"application/json\" \"multipart/bag\" \"multipart/mixed\" \"application/xhtml+xml\" \"font/ttf\" \"font/otf\" \"font/x-woff\" \"image/svg+xml\" \"application/vnd.ms-fontobject\" \"application/ttf\" \"application/x-ttf\" \"application/otf\" \"application/x-otf\" \"application/truetype\" \"application/opentype\" \"application/x-opentype\" \"application/font-woff\" \"application/eot\" \"application/font\" \"application/font-sfnt\" \"application/wasm\" \"application/javascript-binast\" \"application/manifest+json\" \"application/ld+json\" \"application/graphql+json\" \"application/geo+json\"})",
"action": "compress_response",
"action_parameters": {
"algorithms": [
{
"name": "zstd"
},
{
"name": "brotli"
},
{
"name": "gzip"
}
]
}
}
]
}'
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.