Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 27d12d9

Browse files
authored
Added instructions for Fastly Edge Modules: Reroute to other CMS backend (#5865)
* Added instructions for using Fastly Edge Modules to reroute requests to another backend * Updated based on review feedback - Changed title - Added separate "Prerequisites" section - Cleaned up introduction and configuration procedure
1 parent 332f21b commit 27d12d9

File tree

2 files changed

+25
-131
lines changed

2 files changed

+25
-131
lines changed

_data/toc/cloud-guide.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pages:
182182
url: /cloud/cdn/cloud-vcl-custom-snippets.html
183183
exclude_versions: ["2.0"]
184184
children:
185-
- label: Set up redirects to WordPress
185+
- label: Reroute requests to a CMS backend
186186
url: /cloud/cdn/fastly-vcl-wordpress.html
187187

188188
- label: Block referral spam
Lines changed: 24 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
group: cloud-guide
3-
title: Set up redirects to WordPress using Fastly
3+
title: Reroute requests to a CMS backend
44
redirect_from:
55
- /guides/v2.2/cloud/configure/fastly-vcl-wordpress.html
66
- /guides/v2.3/cloud/configure/fastly-vcl-wordpress.html
@@ -9,151 +9,45 @@ functional_areas:
99
- Setup
1010
---
1111

12-
The following example shows how to use a [Fastly Edge Dictionary](https://docs.fastly.com/guides/edge-dictionaries/working-with-dictionaries-using-the-api) with a custom VCL snippet to redirect incoming requests from a {{ site.data.var.ee }} store (`staging.example.com`) to a separate WordPress site (`customer.example.com`) that hosts related content like blog posts and customer stories.
12+
The following procedure describes how to reroute incoming requests from a {{ site.data.var.ee }} store to a separate WordPress site using the Fastly edge module _Other CMS/backend integration_ with an Edge dictionary. You can follow a similar process to reroute requests to other CMS backends.
1313

14-
{: .bs-callout-info }
15-
We recommend adding custom VCL configurations to a Staging environment where you can test them before running against Production.
16-
17-
**Prerequisites**
18-
19-
- Configure the {{ site.var.data.ece }} environment for Fastly services. See [Set up Fastly]({{ page.baseurl }}/cloud/cdn/configure-fastly.html).
20-
21-
- Get credentials to access both the Fastly API and the Magento Admin UI for your {{ site.data.var.ece }} environment.
22-
23-
- Identify the URL paths to redirect to the WordPress backend.
24-
25-
- Submit a support ticket requesting the following Fastly service configuration changes required to use the custom VCL snippet for the WordPress redirects:
26-
27-
- Add the WordPress host to the Fastly backend configuration. Include the domain name for the WordPress host.
28-
29-
- Attach the following request condition to the Wordpress backend.
30-
31-
```json
32-
req.http.X-WP == “1”
33-
```
34-
35-
Incoming requests that match this request condition, which is set through the [custom VCL snippet](#vcl), redirect to the WordPress backend.
36-
37-
## Create an Edge Dictionary of WordPress paths {#edge-dictionary}
38-
39-
Edge Dictionaries create key-value pairs accessible to VCL functions during VCL snippet processing. In this example, you create an edge dictionary that provides the list of URL paths that to redirect from your store to the WordPress backend.
40-
41-
{% include cloud/admin-ui-login-step.md %}
42-
43-
1. Click **Stores** > **Settings** > **Configuration** > **Advanced** > **System**.
44-
45-
1. Expand **Full Page Cache** > **Fastly Configuration** > **Edge dictionaries**.
46-
47-
1. Create the Dictionary container:
48-
49-
- Click **Add container**.
50-
51-
- On the *Container* page, enter a **Dictionary name**—`wordpress_urls`.
52-
53-
- Select **Activate after the change** to enable the dictionary after you create it.
54-
55-
- Click **Upload** to attach the dictionary to your Fastly service configuration.
56-
57-
1. Add the list of URLs for redirection to the the `wordpress_urls` dictionary:
58-
59-
- Click the Settings icon for the `wordpress_urls` dictionary.
60-
61-
![Configure Edge Dictionary]
14+
Edge modules help you create and upload custom VCL code from the Magento Admin UI instead of manually writing the VCL code and uploading it using the Fastly API.
6215

63-
- Add and save key-value pairs in the new dictionary. For this example, each **Key** is a URL path to redirect to the WordPress backend, and the **Value** is 1.
64-
65-
![Add Edge Dictionary Items]
66-
67-
- Click **Cancel** to return to the system configuration page.
68-
69-
1. Click **Save Config**.
70-
71-
1. Refresh the cache according to the notification at the top of the page.
72-
73-
For more information about Edge Dictionaries, see [Creating and using Edge Dictionaries](https://docs.fastly.com/guides/edge-dictionaries/working-with-dictionaries-using-the-api) and [custom VCL snippets](https://docs.fastly.com/guides/edge-dictionaries/working-with-dictionaries-using-the-api#custom-vcl-examples) in the Fastly documentation.
74-
75-
## Create a VCL snippet for the WordPress redirect {#vcl}
76-
77-
The following custom VCL snippet code (JSON format) evaluates incoming requests and redirects those matching a path in the `wordpress_urls` edge dictionary to the WordPress backend specified in the Fastly service configuration.
78-
79-
```json
80-
{
81-
"name": "wordpress_redirect",
82-
"dynamic": "0",
83-
"type": "recv",
84-
"priority": "5",
85-
"content": "if ( req.url.path ~ \"^\\/?([^\\/?]+)\") { if ( table.lookup(wordpress_urls, re.group.1, \"NOTFOUND\") != \"NOTFOUND\" ) { set req.http.X-WP = \"1\"; } }"
86-
}
87-
```
88-
89-
Review the example code and change values as needed:
90-
91-
- `name` — Name for the VCL snippet. For this example, we used `wordpress_redirect`.
92-
93-
- `dynamic` — Value 0 indicates a [regular snippet](https://docs.fastly.com/guides/vcl-snippets/using-regular-vcl-snippets) to upload to the versioned VCL for the Fastly configuration.
94-
95-
- `priority` — Determines when the VCL snippet runs. The priority is `5` to run this snippet code runs before any of the default Magento VCL snippets (`magentomodule_*`) assigned a priority of 50.
96-
97-
- `type` — Specifies a location to insert the snippet in the versioned VCL code. This VCL is a `recv` snippet type which adds the snippet code to the `vcl_recv` subroutine below the default Fastly VCL code and above any objects.
98-
99-
- `content` — The snippet of VCL code to run in one line, without line breaks.
100-
101-
In this example, the VCL code logic extracts the first segment of the path `/mypath/someotherpath`, and then compares the path (`mypath`) to the paths in the `wordpress_urls` dictionary. Requests with matching paths are redirected to the WordPress backend. See the [Fastly VCL reference](https://docs.fastly.com/vcl/reference/) for information about creating Fastly VCL code snippets.
102-
103-
Add the custom VCL snippet to your Fastly service configuration from the Admin UI (requires Fastly module 1.2.58 or later). If you cannot access the Admin UI, save the JSON code example in a file and upload it using the Fastly API. See [Creating a VCL snippet using the Fastly API]({{ page.baseurl }}/cloud/cdn/cloud-vcl-custom-snippets.html#manage-custom-vcl-snippets-using-the-api).
104-
105-
## Add the custom VCL snippet
106-
107-
{% include cloud/admin-ui-login-step.md %}
108-
109-
1. Click **Stores** > **Settings** > **Configuration** > **Advanced** > **System**.
110-
111-
1. Expand **Full Page Cache** > **Fastly Configuration** > **Custom VCL Snippets**.
112-
113-
1. Click **Create Custom Snippet**.
16+
{: .bs-callout-info }
17+
We recommend adding custom VCL configurations to a Staging environment where you can test them before updating the Fastly service configuration in the Production environment.
11418

115-
1. Add the VCL snippet values:
19+
{:.procedure}
20+
Prerequisites
11621

117-
- **Name**`wordpress_redirect`
22+
- Ensure that you are running the latest version of the Fastly CDN module for Magento 2. See [Upgrade the Fastly Module]({{ page.baseurl }}/cloud/cdn/configure-fastly.html#upgrade).
11823

119-
- **Type**`recv`
24+
- Verify the environment configuration for the Fastly service. See [Check Fastly caching]({{ page.baseurl }}/cloud/live/stage-prod-test.html#fastly).
12025

121-
- **Priority**`5`
26+
- You must have Admin credentials to access the Magento Cloud Staging and Production environments.
12227

123-
- **VCL** snippet content:
28+
{:.procedure}
29+
To reroute requests from {{ site.data.var.ee }} to WordPress:
12430

125-
```
126-
if ( req.url.path ~ "^/?([^/?]+)")
127-
{
128-
if ( table.lookup(wordpress_urls, re.group.1, "NOTFOUND") != "NOTFOUND" )
129-
{
130-
set req.http.X-WP = "1";
131-
}
132-
}
133-
```
31+
1. Enable Fastly Edge Modules in the Staging or Production environment.
13432

135-
1. Click **Create** to generate the VCL snippet file with the name pattern `type_priority_name.vcl`, for example `recv_5_wordpress_redirect.vcl`
33+
- Log in to the Magento Admin.
13634

137-
![Create VCL Snippet]
35+
- Navigate to **Stores** > **Configuration** > **Advanced** > **System** > **Full Page Cache** > **Fastly Configuration** > **Advanced**.
13836

139-
1. After the page reloads, click **Upload VCL to Fastly** in the *Fastly Configuration* section to add the file to the Fastly service configuration.
37+
- Set the value for **Fastly Edge Modules** to **Yes**.
14038

141-
1. After the upload completes, refresh the cache according to the notification at the top of the page.
39+
- Save the configuration.
14240

143-
Fastly validates the updated version of the VCL code during the upload process. If the validation fails, edit the custom VCL snippet to fix the issue. Then, upload the VCL again.
41+
1. Identify the URL paths to reroute to the WordPress backend.
14442

145-
{% include cloud/cloud-fastly-manage-vcl-from-admin.md %}
43+
1. Complete the following tasks to configure the Fastly service and create the custom VCL code to reroute the requests to the WordPress backend.
14644

147-
{: .bs-callout-info }
148-
Instead of manually uploading custom VCL snippets, you can add snippets to the `$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 Magento Admin UI. See [Automated custom VCL snippets deployment](https://github.com/fastly/fastly-magento2/blob/master/Documentation/Guides/CUSTOM-VCL-SNIPPETS.md#automated-custom-vcl-snippets-deployment) in the Fastly CDN for Magento 2 module documentation.
45+
- Create an Edge Dictionary that specifies the paths to reroute from the {{ site.data.var.ee }} store to the backend.
14946

150-
<!-- Link definitions -->
47+
- Add the WordPress backend to the Fastly service configuration and attach the request condition for the URL rewrites.
15148

152-
[Configure Edge Dictionary]: {{site.baseurl}}/common/images/cloud/cloud-fastly-edge-dictionary-configure.png
153-
{: width="550px"}
49+
- Configure the *Other CMS/backend integration* Edge Module to handle the URL rewrites from {{ site.data.var.ee }} to the WordPress backend.
15450

155-
[Add Edge Dictionary Items]: {{site.baseurl}}/common/images/cloud/cloud-fastly-edge-dictionary-add-items.png
156-
{: width="550px"}
51+
For detailed instructions, see [Fastly Edge Modules - Other CMS/Backend integration](https://github.com/fastly/fastly-magento2/blob/master/Documentation/Guides/Edge-Modules/EDGE-MODULE-OTHER-CMS-INTEGRATION.md) in the _Fastly CDN module for Magento 2_ documentation.
15752

158-
[Create VCL Snippet]: {{site.baseurl}}/common/images/cloud/cloud-fastly-create-vcl-snippet.png
159-
{: width="550px"}
53+
1. After updating the Fastly service configuration, test your {{ site.var.data.ee }} store to ensure that the specified URL requests for WordPress are rerouted correctly.

0 commit comments

Comments
 (0)