This topic describes how to set a time-to-live (TTL) value for HTTP status codes that are returned to requests for static resources in a specified directory or with specified file extensions. This allows DCDN edge nodes to directly return HTTP status codes to requests and reduces loads on origin servers.

Scenarios

HTTP 2xx status codes indicate that DCDN edge nodes have retrieved the requested resources from the origin server. In this case, the origin server returns an HTTP 2xx status code to the DCDN edge nodes. Then, the DCDN edge nodes process the requests based on cache expiration rules. If the origin server fails to return HTTP status codes, such as an HTTP 2xx status code, to the DCDN edge nodes, and you do not want the origin server to respond to every request, you can set a TTL value for HTTP status codes. Then, DCDN edge nodes directly return HTTP status codes to requests to reduce loads on the origin server.

Note
  • HTTP 303, 304, 401, 407, 600, and 601 status codes are not supported.
  • If the Cache-Control, Pragma or Expires header is configured on the origin server, Alibaba Cloud DCDN caches the following HTTP status codes based on the Cache-Control, Pragma or Expires directive: 204, 305, 400, 403, 404, 405, 414, 500, 501, 502, 503, and 504. If you do not set a TTL value for these HTTP status codes, or the HTTP response header of the origin server does not contain the field Cache-Control, Pragma or Expires, the TTL value is set to 1 second by default.

Procedure

  1. Log on to the DCDN console.
  2. In the left-side navigation pane, click Domain Names.
  3. On the Configure page, find the domain name that you want to manage and click Domain Names in the Actions column.
  4. In the left-side navigation pane on the details page of the specified domain name, click Caching.
  5. Click the Status Codes and Expiration Time tab.
  6. Click Add to create an expiration rule for HTTP status codes.
    Create an expiration rule for HTTP status codes
    Parameter Description
    Type You can select Directory or File Extension. Select a type based on your business requirements.
    Note If you set TTL values for the HTTP status codes of both a directory and files with specified extensions, whichever rule that is set first takes effect. All other rules are ignored.
    Object
    • If you select Directory, take note of the following rules:
      • You can add only one directory in each rule.
      • You can enter a full path. It must start with a forward slash (/), for example, /directory/aaa.
    • If you select File Extension, take note of the following rules:
      • You can enter one or more file extensions. Separate file extensions with commas (,), for example, JPG,TXT.
      • You cannot use an asterisk (*) to specify all file types.
    Expire In
    • You can set a TTL value for 4xx and 5xx HTTP status codes. The TTL value is in seconds. Separate HTTP status codes with commas (,), for example, 4xx=10,5xx=15.
    • You cannot set a TTL value for 2xx or 3xx status codes. You can set a TTL value only for specific HTTP status codes, including 201 and 302 status codes. The TTL value is measured in seconds. For example, you can set 201=10,302=15.
  7. Click OK.

    After an expiration rule for HTTP status codes is created, it is displayed on the Status Code Expiration Time tab. You can Modify or Delete the rule.

Related API operations

BatchAddDcdnDomain