You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
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
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.
13
13
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.
- 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.
62
15
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.
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).
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.
114
18
115
-
1. Add the VCL snippet values:
19
+
{:.procedure}
20
+
Prerequisites
116
21
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).
118
23
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).
120
25
121
-
-**Priority** — `5`
26
+
- You must have Admin credentials to access the Magento Cloud Staging and Production environments.
122
27
123
-
-**VCL** snippet content:
28
+
{:.procedure}
29
+
To reroute requests from {{ site.data.var.ee }} to WordPress:
124
30
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.
134
32
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`
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**.
140
38
141
-
1. After the upload completes, refresh the cache according to the notification at the top of the page.
39
+
- Save the configuration.
142
40
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.
144
42
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.
146
44
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.
149
46
150
-
<!-- Link definitions -->
47
+
- Add the WordPress backend to the Fastly service configuration and attach the request condition for the URL rewrites.
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.
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