Skip to content

Commit 2c9573c

Browse files
Merge pull request #370 from commerce-docs/troubleshooting-vcl-deletion
add troubleshooting section specifically for vcl deletion issue
2 parents e9fea45 + 6d2ca8f commit 2c9573c

File tree

1 file changed

+52
-19
lines changed

1 file changed

+52
-19
lines changed

src/content/docs/setup/configuration/content-delivery-network.mdx

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ Only the homepage is delivered by Edge Delivery Services. All Commerce functiona
7676
:::note
7777
A common pattern is to move all Edge Delivery Services code into a subfolder called `aem`, and then route any path starting with `aem` to Edge Delivery Services.
7878
:::
79-
79+
8080
For general information on setting up Fastly for Adobe Commerce and accessing the Adobe Commerce Admin, see [Fastly services overview](https://experienceleague.adobe.com/en/docs/commerce-cloud-service/user-guide/cdn/fastly).
8181

82-
## Backend configuration
82+
## Backend configuration
8383

8484
The first step is to configure a backend for each origin/service that Fastly needs to route to, which includes the following:
8585

@@ -95,7 +95,7 @@ The Fastly configuration instructions on this page are based on the [`fastly-mag
9595

9696
1. Log in to the Adobe Commerce Admin.
9797

98-
1. Click **Stores** > _Settings__ > **Configuration** > **Advanced** > **System** > **Full Page Cache** > **Fastly Configuration** > **Backend Settings** > **Create**.
98+
1. Click **Stores** > **Settings** > **Configuration** > **Advanced** > **System** > **Full Page Cache** > **Fastly Configuration** > **Backend Settings** > **Create**.
9999

100100
1. Enter a name for the Edge Delivery Services backend.
101101

@@ -196,17 +196,17 @@ The following `recv` snippet has the following purpose:
196196

197197
```txt
198198
unset req.http.x-commerce;
199-
199+
200200
# Catalog Service
201201
if (req.url.path ~ "^/cs-graphql$") {
202202
# Disable Commerce WAF as it can interfere with some queries
203203
set req.http.bypasswaf = "true";
204-
205-
# Forward to Catalog Service GraphQL
204+
205+
# Forward to Catalog Service GraphQL
206206
set req.backend = F_catalog_service;
207207
set req.http.host = "catalog-service.adobe.io";
208208
set req.url = regsub(req.url, "^/cs-graphql", "/graphql");
209-
209+
210210
# Remove cookies
211211
unset req.http.Cookie;
212212
}
@@ -221,20 +221,20 @@ else
221221
if (req.url ~ "^/configs-(stage|dev)\.json$") {
222222
error 404 "Not Found";
223223
}
224-
224+
225225
# Everything else is considered Edge Delivery Services
226226
set req.backend = F_edge_delivery;
227227
# Restore accepted encoding
228228
set req.http.Accept-Encoding = req.http.Fastly-Orig-Accept-Encoding;
229229
if (req.url.path !~ "/media_[0-9a-f]{40,}[/a-zA-Z0-9_-]*\.[0-9a-z]+$"
230230
&& req.url.ext !~ "(?i)^(gif|png|jpe?g|webp)$"
231231
&& req.url.ext != "json"
232-
&& req.url.path != "/.auth") {
232+
&& req.url.path != "/.auth") {
233233
# trim the query string to improve caching
234234
set req.url = req.url.path;
235235
# replace some special characters with a dash because Edge doesn't support them
236236
set req.url = regsuball(req.url, "[()]", "-");
237-
237+
238238
}
239239
}
240240
```
@@ -255,10 +255,10 @@ if (req.backend == F_edge_delivery) {
255255
set bereq.http.X-BYO-CDN-Type = "fastly";
256256
set bereq.http.X-Push-Invalidation = "enabled";
257257
}
258-
258+
259259
if (!req.http.x-commerce) {
260260
return(pass);
261-
}
261+
}
262262
```
263263

264264
:::note
@@ -279,7 +279,7 @@ if (req.backend == F_edge_delivery) {
279279
set bereq.http.X-BYO-CDN-Type = "fastly";
280280
set bereq.http.X-Push-Invalidation = "enabled";
281281
}
282-
282+
283283
if (!req.http.x-commerce) {
284284
return(fetch);
285285
}
@@ -315,7 +315,7 @@ This comes from the Edge Delivery Services [Fastly setup](https://www.aem.live/d
315315
```txt
316316
if (req.backend == F_edge_delivery) {
317317
unset resp.http.Age;
318-
318+
319319
if (req.url.path !~ "\.plain\.html$") {
320320
unset resp.http.X-Robots-Tag;
321321
}
@@ -349,8 +349,8 @@ pragma optional_param geoip_opt_in true;
349349
350350
# Snippet GeoIpRedirect
351351
declare local var.countryCode STRING;
352-
353-
# Only apply redirection if the URL has no country-specific path
352+
353+
# Only apply redirection if the URL has no country-specific path
354354
355355
# This snippet performs a GeoIP-based redirection. It checks if the request is made to the
356356
# "example.com" domain and if the URL path is either the root ("/") or empty. If these conditions are met, it
@@ -590,7 +590,7 @@ x-cache-hits: 0, 37, 1, 0
590590
```
591591

592592
* `content-encoding`: Should be `gzip` or `br` for things like JS assets and HTML files, which should be encoded from origin.
593-
* `surrogate-key`: Should not be `text`. If the value is `text`, make sure you have correctly configured the `fetch` VCL snippet to return `deliver` for Edge Delivery Servicespaths.
593+
* `surrogate-key`: Should not be `text`. If the value is `text`, make sure you have correctly configured the `fetch` VCL snippet to return `deliver` for Edge Delivery Servicespaths.
594594

595595
The reason for this validation step is that the [default Commerce Fastly VCL](https://github.com/fastly/fastly-magento2/blob/fdd616cd0f945530e02e92e594ca00fd7990f557/etc/vcl_snippets/fetch.vcl#L113) sets this. This overwrites the Edge Delivery Services surrogate key, which is required for cache invalidation to work correctly when a page is re-published.
596596

@@ -679,6 +679,39 @@ Ensure that the base URL change is propagated to Catalog Service. You can do thi
679679

680680
![Commerce base URL](@images/implementation/commerce-base-url.png)
681681

682-
## Debugging
682+
## Troubleshooting
683+
684+
<Aside type="note" title="It's confusing - we get it">
685+
Fastly VCL and CDN configuration can be a bit overwhelming at first. Here's a collection of troubleshooting steps that might help you if you have problems.
686+
</Aside>
687+
688+
### Fastly API quick reference
689+
690+
With your Fastly API Token you can make requests against the Fastly API for information or data that may be otherwise inaccessible. You can find your API Token in your Commerce Admin view under **Stores** > **Settings** > **Configuration** > **Advanced** > **System** > **Full Page Cache** > **Fastly Configuration**.
691+
692+
Here's a quick reference of things you can do with your API Token. See [Fastly's API documentation](https://www.fastly.com/documentation/reference/api/) for more details.
693+
694+
```bash
695+
# retrieve active version
696+
curl -H "Fastly-Key: API_TOKEN" "https://api.fastly.com/service/SERVICE_ID/version"
697+
698+
# retrieve full, generated VCL
699+
curl -H "Fastly-Key: API_TOKEN" "https://api.fastly.com/service/SERVICE_ID/version/VERSION/generated_vcl"
700+
701+
# retrieve all snippets
702+
curl -H "Fastly-Key: API_TOKEN" "https://api.fastly.com/service/SERVICE_ID/version/VERSION/snippet"
703+
```
704+
705+
### Missing snippets
706+
707+
Fastly maintains a "version" of your snippets remotely on their servers. These versions are never pulled "down" to your Commerce environment, but can be "pushed" from your environment to Fastly. Unintentional local changes can cause things to become out of sync.
708+
709+
For example, renaming a snippet actually creates a new snippet with the new name, and does not delete the old one. You should not rename snippets unless you must. See [this issue](https://github.com/fastly/fastly-magento2/issues/708) for more information.
710+
711+
Your environment stores custom VCL snippets in the `var/vcl_snippets_custom/` directory. If you delete that directory or its contents, you will not be able to view, edit, or modify the snippets, even though they remain active in Fastly."
712+
713+
To resolve this, you should use the Fastly API to "pull" all snippets and then place them back in that folder (with permission **775**). The following table details how to construct the file correctly:
683714

684-
The full VCL script can be viewed to see which VCL snippet is applied and in which order. In the Commerce Admin, go to **Tools** (sibling of the VCL Snippets dropdown), select "List all Versions" and click the eye icon of the latest version to view the full generated VCL.
715+
| `var` directory filename | Admin Panel Field | Fastly Fields |
716+
|--------------------------------|----------------------------------------------|--------------------------------------------------------|
717+
| _recv_100_snippetrecv.vcl_ | Type: _recv_ <br/> Priority: _100_ <br/> Name: _snippetrecv_ | Type: _recv_ <br/> Priority: _100_ <br/> Name: _magentomodule_snippetrecv_ |

0 commit comments

Comments
 (0)