Cloud CDN이 사용 설정되어 있는지 확인합니다. 자세한 내용은 Cloud CDN 사용을 참조하세요.
필요한 경우 Google Cloud CLI를 최신 버전으로 업데이트합니다.
gcloud components update
상태 코드 및 기본 TTL
음성 캐싱은 다음 표에 나열된 특정 상태 코드에 적용됩니다.
Cloud CDN은 다음과 같은 기본 TTL을 상태 코드에 적용합니다.
상태 코드
의미
TTL
HTTP 300
다중 선택
10분
HTTP 301 및 308
영구 리디렉션
10분
HTTP 302 및 307
임시 리디렉션
기본적으로 캐시되지 않음
HTTP 404
찾을 수 없음
120초
HTTP 405
메서드 없음
60초
HTTP 410
없음
120초
HTTP 451
법적 사유로 사용할 수 없음
120초
HTTP 501
구현되지 않음
60초
음성 캐싱을 사용하여 이러한 기본값을 재정의하면 지정된 HTTP 상태 코드에 캐시 TTL을 설정할 수 있습니다.
음성 캐싱 설정
음성 캐싱을 사용하면 성공뿐만 아니라 실패도 캐시하도록 서비스를 구성할 수 있습니다. 이를 통해 Cloud CDN은 성공적인 응답을 생성하는 요청으로부터 출처를 보호하는 것과 마찬가지로 오류를 생성하는 요청(예: 404 Not Found)으로부터 출처를 보호할 수 있습니다.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets
PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/BACKEND_BUCKET
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices
PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE
negativeCachingPolicy 설정을 구성하려면 음성 캐싱을 사용 설정해야 합니다. 정책을 생략하고 negativeCaching을 사용 설정하면 Cloud CDN은 상태 코드 및 기본 TTL에 나열된 기본값을 사용합니다.
음성 캐싱 정책을 지정할 때는 캐시할 모든 응답 코드에 캐시 TTL을 지정해야 합니다. Cloud CDN은 정책이 존재하면 어떠한 기본 음성 캐싱도 적용하지 않습니다.
STATUS_CODE에는 다음 HTTP 상태 코드를 지정할 수 있습니다.
300, 301, 302, 307, 308
404, 405, 410, 421, 451
501
각 상태 코드에는 응답을 캐시할 시간(초)을 지정할 수 있습니다.
상태 코드의 음성 캐싱을 중지하려면 음성 캐싱 정책에서 코드를 제외합니다.
최대 허용 값은 1, 800초(30분)입니다. 하지만 자주 액세스되지 않는 객체는 정의된 TTL 이전에 캐시에서 삭제될 수 있습니다.
캐시 모드가 CACHE_ALL_STATIC 또는 USE_ORIGIN_HEADERS로 설정되면 Cache-Control 또는 Expires 헤더가 없는 지정된 응답 코드가 있는 응답에 음성 캐싱이 적용됩니다.
캐시 모드가 FORCE_CACHE_ALL로 설정되면 음성 캐싱이 출처에서 설정한 모든 캐싱 헤더를 재정의하고, Cloud CDN은 TTL에 지정된 기간 동안 응답을 캐시하거나 TTL이 설정되지 않은 경우 어떠한 응답도 캐시하지 않습니다.
또한 캐시 모드가 FORCE_CACHE_ALL로 설정되면 Cloud CDN은 Cache-Control 헤더에서 클라이언트로 전송하는 max-age도 수정합니다. 특히, 특정 오류에 TTL 설정이 구성되어 있으면 Cloud CDN은 해당 TTL 설정과 client_ttl 구성 설정 중 더 작은 값을 사용하고 해당 값으로 Cache-Control: public,max-age=N 헤더를 전송합니다. 특정 오류에 TTL 설정이 구성되어 있지 않으면 Cloud CDN은 출처에서 보낸 Cache-Control 헤더를 모두 삭제합니다. 또한 Cloud CDN은 출처에서 보낸 Expires 헤더도 항상 모두 삭제합니다.
처음에 원본에 음성 캐싱이 사용 설정되었지만 이후에 수동으로 또는 특정 응답 코드에 대한 캐싱을 중지하여 사용 중지된 경우, 캐시된 오류 응답은 Cache-Control 또는 Expires 헤더를 기준으로만 유효한 것으로 간주됩니다. 따라서 음성 캐싱이 사용 중지되면 헤더에 캐싱 기간 지시어가 없는 응답이 캐시에서 제공되지 않습니다.
Cloud CDN은 GET 요청에 대한 응답으로 캐싱합니다. 자세한 내용은 캐시 가능한 콘텐츠를 참조하세요.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets
PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/BACKEND_BUCKET
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices
PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-05(UTC)"],[[["\u003cp\u003eNegative caching allows setting distinct Time-To-Live (TTL) values for various HTTP status codes, offering fine-grained control over caching errors and redirects.\u003c/p\u003e\n"],["\u003cp\u003eConfiguring negative caching can reduce origin load and enhance user experience by minimizing response latency for common errors.\u003c/p\u003e\n"],["\u003cp\u003eDefault TTL values are provided for specific status codes like 300, 301, 308, 404, 405, 410, 451, and 501, but can be overridden using negative caching policies.\u003c/p\u003e\n"],["\u003cp\u003eNegative caching can be enabled or disabled through the Google Cloud console, \u003ccode\u003egcloud\u003c/code\u003e CLI, or API, and it requires specifying TTL values for all response codes to be cached.\u003c/p\u003e\n"],["\u003cp\u003eWhen negative caching is active, Cloud CDN manages the \u003ccode\u003eCache-Control\u003c/code\u003e header sent to clients, including setting \u003ccode\u003emax-age\u003c/code\u003e based on configured TTL values.\u003c/p\u003e\n"]]],[],null,["# Use negative caching\n\nThis page provides instructions for using negative caching with\nCloud CDN. Negative caching lets you set a different TTL for each status\ncode.\n\nThe reason to do this is to apply fine-grained control over caching for common\nerrors or redirects. This can reduce the load on your origins and improve the\nend-user experience by reducing response latency.\n\nBefore you begin\n----------------\n\n- Read about [cache modes and static content](/cdn/docs/caching#cache-modes).\n\n- Ensure that Cloud CDN is enabled; for instructions, see\n [Using Cloud CDN](/cdn/docs/using-cdn).\n\n- If necessary, update to the latest version of the Google Cloud CLI:\n\n ```\n gcloud components update\n ```\n | **Note:** Make sure that you're using gcloud CLI version `316.0.0` or later.\n\nStatus codes and default TTLs\n-----------------------------\n\nNegative caching applies to specific status codes, which are listed in the\nfollowing table.\n| **Note:** The TTL values for HTTP success codes (HTTP 2xx) are controlled by the values of [default TTL and max TTL](/cdn/docs/using-ttl-overrides).\n\nCloud CDN applies the following default TTLs to these status codes:\n\nYou can override these default values by using negative caching to set a cache\nTTL for the specified HTTP status code.\n\nSetting up negative caching\n---------------------------\n\nNegative caching lets you configure your service to cache failures as well as\nsuccesses. This allows Cloud CDN to shield origins from requests that\ngenerate errors (like 404 Not Found) in the same way that it shields origins\nfrom requests that generate successful responses. \n\n### Console\n\n1. In the Google Cloud console, go to the **Load Balancing** page.\n\n [Go to the Load balancing page](https://console.cloud.google.com/networking/loadbalancing/list)\n2. Click the name of your external Application Load Balancer.\n3. Click **Edit** edit.\n4. In **Backend configuration** , select a backend and click **Edit** edit.\n5. Make sure that **Enable Cloud CDN** is selected.\n6. At the bottom of the window, click **Advanced configurations**.\n7. Click **Enable negative caching**.\n8. Click **Add negative caching policy** .\n 1. Enter an **HTTP status code**.\n 2. Select a **Cache time to live (TTL)**.\n9. Click **Update**.\n10. Click **Update** again.\n\n### gcloud\n\nFor backend buckets, use the [gcloud compute backend-buckets\ncreate](/sdk/gcloud/reference/compute/backend-buckets/create) or\n[gcloud compute backend-buckets\nupdate](/sdk/gcloud/reference/compute/backend-buckets/update) command\nwith the `--negative-caching` flag.\n\nFor backend services, use the [gcloud compute backend-services\ncreate](/sdk/gcloud/reference/compute/backend-services/create) or\n[gcloud compute backend-services\nupdate](/sdk/gcloud/reference/compute/backend-services/update) command\nwith the `--negative-caching` flag. \n\n```\ngcloud compute backend-buckets (create | update) BACKEND_BUCKET_NAME\n --negative-caching\n``` \n\n```\ngcloud compute backend-services (create | update) BACKEND_SERVICE_NAME\n --negative-caching\n```\n\nTo enable negative caching of only two specific error responses,\nfor example, set responses with status code `404` to be cached for 60\nseconds, and responses with status code `405` to be cached for 120 seconds. \n\n```\ngcloud compute backend-services update BACKEND_SERVICE_NAME \\\n --negative-caching \\\n --cache-mode=CACHE_ALL_STATIC \\\n --default-ttl=86400 \\\n --negative-caching-policy='404=60,405=120'\n```\n\n### api\n\nFor backend buckets, use the\n[Method: backendBuckets.insert](/compute/docs/reference/rest/v1/backendBuckets/insert) or\n[Method: backendBuckets.update](/compute/docs/reference/rest/v1/backendBuckets/update)\nAPI call.\n\nFor backend services, use the\n[Method: backendServices.insert](/compute/docs/reference/rest/v1/backendServices/insert) or\n[Method: backendServices.update](/compute/docs/reference/rest/v1/backendServices/update)\nAPI call.\n\nUse one of the following API calls: \n\n```\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets\nPUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/BACKEND_BUCKET\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices\nPUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE\n```\n\nAdd the following snippet to the JSON request body: \n\n```\n\"cdnPolicy\": {\n \"negativeCaching\": ON,\n \"negativeCachingPolicy\": [\n {\n \"code\": STATUS_CODE,\n \"ttl\": TTL_SECONDS\n }\n ]\n}\n```\n\nNegative caching must be enabled to configure the `negativeCachingPolicy`\nsettings. If you omit the policy and have `negativeCaching` enabled,\nCloud CDN uses the default values listed in [Status codes and default\nTTLs](#status-code-default-ttl).\n\nWhen specifying a negative caching policy, make sure to specify a cache TTL for\n*all* response codes that you want to cache. Cloud CDN doesn't apply\nany default negative caching when a policy exists.\n\nFor \u003cvar translate=\"no\"\u003eSTATUS_CODE\u003c/var\u003e, you can specify the following HTTP status codes:\n\n- `300`, `301`, `302`, `307`, `308`\n- `404`, `405`, `410`, `421`, `451`\n- `501`\n\nFor each status code, you can specify a number of seconds to cache responses.\nTo disable negative caching for the status code, exclude the code from your\nnegative caching policy.\n| **Note:** Explicitly including a code and setting the TTL to `0` disables caching, but doing so is not recommended because the use of a TTL value of `0` in this context is different from other uses in Cloud CDN. For example, a `max-age=0` directive in a response `cache-control` header means that the cache must always revalidate the response, rather than that the response is not cacehable.\n\nThe maximum allowed value is 1800 seconds (30 minutes); however, infrequently\naccessed objects might be evicted from the cache before the defined TTL.\n\nWhen the cache mode is set to `CACHE_ALL_STATIC` or `USE_ORIGIN_HEADERS`,\nnegative caching is applied to responses with the specified response code that\nlack any `Cache-Control` or `Expires` headers.\n\nWhen the cache mode is set to `FORCE_CACHE_ALL`, negative caching overrides any\ncaching headers set by the origin, and Cloud CDN will cache the\nresponse for the length of time specified by the TTL, or will not cache it at\nall if no TTL is set.\n\nIn addition, when the cache mode is set to `FORCE_CACHE_ALL`, Cloud CDN\nwill also modify the `max-age` sent to the client in the `Cache-Control`\nheader. In particular, if a given error has a configured TTL setting,\nCloud CDN will take the lesser of that TTL setting and the `client_ttl`\nconfiguration setting, and send a `Cache-Control: public,max-age=N` header with\nthat value. If a given error does not have a configured TTL setting,\nCloud CDN will remove any `Cache-Control` header sent by the\norigin. Cloud CDN will also always remove any `Expires` header sent by\nthe origin.\n\nIf an origin has negative caching initially enabled but then disabled (either\nmanually or by disabling caching for a particular response code), cached error\nresponses are considered valid based only on their `Cache-Control` or `Expires`\nheaders. Therefore, once negative caching is disabled, a response with no\ncaching age directives in its headers is not served from cache.\n\nCloud CDN caches in response to `GET` requests. For more information, see\n[Cacheable content](/cdn/docs/caching#cacheability).\n\nEach cache entry is identified by a [cache key](/cdn/docs/caching#cache-keys).\n\n### Disable negative caching\n\n### Console\n\n1. In the Google Cloud console, go to the **Load Balancing** page.\n\n [Go to the Load balancing page](https://console.cloud.google.com/networking/loadbalancing/list)\n2. Click the name of your external Application Load Balancer.\n3. Click **Edit** edit.\n4. In **Backend configuration** , select a backend and click **Edit** edit.\n5. Make sure that **Enable Cloud CDN** is selected.\n6. At the bottom of the window, click **Advanced configurations**.\n7. Clear the checkbox next to **Enable negative caching**.\n8. Click **Update**.\n9. Click **Update** again.\n\n### gcloud\n\nFor backend buckets, use the [gcloud compute backend-buckets\ncreate](/sdk/gcloud/reference/compute/backend-buckets/create) or\n[gcloud compute backend-buckets\nupdate](/sdk/gcloud/reference/compute/backend-buckets/update) command\nwith the `--no-negative-caching` flag.\n\nFor backend services, use the [gcloud compute backend-services\ncreate](/sdk/gcloud/reference/compute/backend-services/create) or\n[gcloud compute backend-services\nupdate](/sdk/gcloud/reference/compute/backend-services/update) command\nwith the `--no-negative-caching` flag. \n\n```\ngcloud compute backend-services (create | update) (BACKEND_SERVICE_NAME | BACKEND_BUCKET_NAME)\n --no-negative-caching\n```\n\n### api\n\nFor backend buckets, use the\n[Method: backendBuckets.insert](/compute/docs/reference/rest/v1/backendBuckets/insert) or\n[Method: backendBuckets.update](/compute/docs/reference/rest/v1/backendBuckets/update)\nAPI call.\n\nFor backend services, use the\n[Method: backendServices.insert](/compute/docs/reference/rest/v1/backendServices/insert) or\n[Method: backendServices.update](/compute/docs/reference/rest/v1/backendServices/update)\nAPI call.\n\nUse one of the following API calls: \n\n```\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets\nPUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/BACKEND_BUCKET\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices\nPUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE\n```\n\nAdd the following snippet to the JSON request body: \n\n```\n\"cdnPolicy\": {\n \"negativeCaching\": OFF\n}\n```"]]