快速設定

The following screenshots illustrate how to configure Fastly to deliver content. Essential settings are marked with a red circle.

Setup push invalidation for Fastly

Push invalidation automatically purges content on the customer’s production CDN (e.g. www.yourdomain.com), whenever an author publishes content changes.

Content is purged by url and by cache tag/key.

Push invalidation is enabled by adding specific properties to the project’s configuration (an Excel workbook named .helix/config.xlsx in Sharepoint or a Google Sheet named .helix/config in Google Drive).

Configuration properties:

key
value
comment
cdn.prod.host
<Production Host>
Host name of production site, e.g. www.yourdomain.com
cdn.prod.type
fastly
cdn.prod.serviceId
<Fastly Service ID>
Service ID of production service
cdn.prod.authToken
<Fastly API Token>

To create a Fastly API Token,

  • go to Personal API Tokens,
  • click on “Create Token”,
  • enter a name (e.g. "Production Site Purge Token"),
  • select “A specific service” and your production service from the drop-down list,
  • check the “Purge select content (purge_select) — Purge by URL or surrogate key” check box,
  • select “Never expire”,
  • click on “Create Token”,
  • copy the generated token value shown in the pop-up window.

You can validate the credentials with this tool.

Create a Fastly service

Go to the Fastly Management UI and select Create Service, CDN.

Add Domain

Add your production domain (e.g. www.mydomain.com):

Configure Origin

Add your origin (e.g. main--mysite--hlxsites.aem.live) and keep the default settings for:

  • Override default host
  • Default compression
  • Force TLS & HSTS

In the new configuration, click “Edit configuration” in the top right corner and “clone version 1 to edit”.

In the sidebar, select “Hosts” underneath “Origins” and click the pencil icon to change host settings.

Scroll down and change Shielding to Ashburn Metro (IAD) (non-mandatory but recommended setting):

Don’t forget to “update”.

Create VCL Snippets

Create a VCL snippet for the recv subroutine with the following VCL code:

if (fastly.ff.visits_this_service == 0) {
  # edge delivery node
  if (req.url.qs != "") {
    # remember query string
    set req.http.X-QS = req.url.qs;

    if (req.url.path !~ "/media_[0-9a-f]{40,}[/a-zA-Z0-9_-]*\.[0-9a-z]+$"
      && req.url.ext !~ "(?i)^(gif|png|jpe?g|webp)$"
      && req.url.ext != "json"
      && req.url.path != "/.auth") {
      # strip query string from request url
      set req.url = req.url.path;
    }
  }
}

Create additional VCL snippets for the miss and pass subroutines with the following VCL code:

set bereq.http.X-BYO-CDN-Type = "fastly";
set bereq.http.X-Push-Invalidation = "enabled";

Note: The X-Push-Invalidation: enabled request header enables the push invalidation including long cache TTLs.

Create a deliver snippet with the following VCL code:

if (fastly.ff.visits_this_service == 0) {
  # on edge delivery node
  if (
    http_status_matches(resp.status, "301,302,303,307,308")
    && req.http.X-QS
    && resp.http.location
    && resp.http.location !~ "\?.*\z"
  ) {
    # preserve request query string in redirect location
    set resp.http.location = resp.http.location "?" req.http.X-QS;
  }
}

Finally create a deliver snippet with the following VCL code:

unset resp.http.Age;

if (req.url.path !~ "\.plain\.html$") {
  unset resp.http.X-Robots-Tag;
}

After completing all steps and activating the service version you should be all set:

Optional: Authenticate Origin Requests

If you have enabled token-based Site Authentication, navigate in the sidebar to Content → Headers, then “create a header” with following settings:

  • Name: Origin Authentication
  • Type: Request/Set
  • Destination: http.Authorization
  • Source: "token <your-token-here>" (don’t forget the quotes, and replace <your-token-here> with the site token retrieved in token-based Site Authentication – the token starts with hlx_)
  • Ignore if set: no
  • Priority: 10

Note

Your Fastly setup should not use Fastly’s Next Generation Web Application Firewall for requests that are going against aem.live or any other Edge Delivery Services origin. Enabling WAF with Edge Delivery Services can lead to erroneous content being delivered.

Edge Delivery Services needs no Web Application Firewall, as it is running on hardened, shared, and ultra-scalable infrastructure. Requests that a WAF would typically intercept are terminated in our CDNs.

recommendation-more-help
fbcff2a9-b6fe-4574-b04a-21e75df764ab