Custom VCL to bypass Fastly cache
You can create a custom VCL snippet to bypass the Fastly cache so you can troubleshoot request traffic to the origin server. For example, you can create a snippet to determine whether site issues are caused by caching, or to troubleshoot headers.
You can configure the snippet to bypass Fastly caching for requests from a specific IP address or URL.
Prerequisites:
-
Your environment must be configured to use the Fastly CDN. See Configure Fastly services.
-
Ensure that you are running the latest version of the Fastly CDN module for Magento 2. See Upgrade the Fastly Module.
-
Verify the environment configuration for the Fastly service. See Check Fastly caching.
-
You must have Admin credentials to access the Staging and Production environments.
To bypass Fastly cache based on IP address or URL:
-
Log in to the Admin.
-
Click Stores > Settings > Configuration > Advanced > System.
-
Expand Full Page Cache > Fastly Configuration > Custom VCL Snippets.
-
Click Create Custom Snippet.
-
Add the VCL snippet values:
-
Name —
bypass_fastly
-
Type —
recv
-
Priority —
5
-
VCL snippet content —
The following example bypasses Fastly for a specific IP address:
code language-conf if (client.ip == "<Your IPv4 IP address>" || client.ip == "<Your IPv6 IP address>") { return(pass); }
The following example bypasses Fastly for a specific URL pattern:
code language-conf if (req.url ~ "/media/feeds/GoogleShoppingHiVisNew.xml") { return (pass);}
For an exact URL match, use the
==
operator instead of the~
operator. See the Fastly VCL reference for details.
-
-
Click Create.
-
After the page reloads, click Upload VCL to Fastly in the Fastly Configuration section.
-
After the upload completes, refresh the cache according to the notification at the top of the page.
Fastly validates the updated VCL version during the upload process. If the validation fails, edit your custom VCL snippet to fix any issues. Then, upload the VCL again.
After you add the VCL snippet, you can use cURL commands to submit requests to the origin server from the specified IP address or URL as shown in the following example:
curl -svo /dev/null www.example.com/index.html
Then, inspect the response to troubleshoot issues with the uncached content.
$MAGENTO_CLOUD_APP_DIR/var/vcl_snippets_custom
directory in your environment. Snippets in this directory upload automatically when you click upload VCL to Fastly in the Commerce Admin. See Automated custom VCL snippets deployment in the Fastly CDN module for Magento 2 documentation.Modify the custom VCL snippet
-
Log in to the Admin.
-
Click Stores > Settings > Configuration > Advanced > System.
-
Expand Full Page Cache > Fastly Configuration > Custom VCL Snippets.
-
In the Action column, click the settings icon next to the snippet to edit.
-
After the page reloads, click Upload VCL to Fastly in the Fastly Configuration section.
-
After the upload completes, refresh the cache according to the notification at the top of the page.
Delete the custom VCL snippet
-
Log in to the Admin.
-
Click Stores > Settings > Configuration > Advanced > System.
-
Expand Full Page Cache > Fastly Configuration > Custom VCL Snippets.
-
In the Action column, click the trash icon next to the snippet to delete.
-
On the next modal window, click DELETE and activate a new version.