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.
Copy file name to clipboardExpand all lines: src/cloud/cdn/cloud-vcl-custom-snippets.md
+4-5Lines changed: 4 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ You can create and manage custom VCL snippets from the Magento Admin UI or by us
44
44
45
45
### Example VCL snippet code {#vcl-curl}
46
46
47
-
The following example shows the custom VCL snippet that filters traffic by client IP address in JSON format.
47
+
The following example shows the custom VCL snippet (JSON format) that filters traffic by client IP address:
48
48
49
49
```json
50
50
{
@@ -59,7 +59,7 @@ The following example shows the custom VCL snippet that filters traffic by clien
59
59
```
60
60
61
61
{: .bs-callout-warning}
62
-
In this example, the VCL code is formatted as a JSON payload that can be saved to a file and submitted in a Fastly API request. If you submit the VCL code snippet from the Magento Admin UI, or as a JSON string using the Fastly API, you must escape special characters to prevent validation errors. See the example in [Secure the Magento Admin UI]({{ site.baseurl }}/cloud/cdn/fastly-vcl-whitelist.html#vcl).
62
+
In this example, the VCL code is formatted as a JSON payload that can be saved to a file and submitted in a Fastly API request. When sending the snippet as JSON for an API request, you must use a backslash to escape special characters in the code to prevent JSON validation errors. See [Using dynamic VCL snippets](https://docs.fastly.com/vcl/vcl-snippets/)in the Fastly VCL documentation. If you submit the VCL snippet from the Magento Admin UI, you do not have to escape special characters.
63
63
64
64
The VCL logic in the `content` field performs the following actions:
65
65
@@ -90,8 +90,7 @@ The *Custom VCL snippets* view shows only the snippets added through the Magento
90
90
91
91
See the following examples that show how to create and manage custom VCL snippets from the Magento Admin UI:
92
92
93
-
-[Secure access to the Magento Admin UI]({{ site.baseurl }}/cloud/cdn/fastly-vcl-whitelist.html)
94
-
-[Set up redirects to WordPress using Fastly]({{ site.baseurl }}/cloud/cdn/fastly-vcl-wordpress.html)
93
+
-[Custom VCL for IP allowlist]({{ site.baseurl }}/cloud/cdn/fastly-vcl-whitelist.html)
Copy file name to clipboardExpand all lines: src/cloud/cdn/fastly-vcl-badreferer.md
+10-12Lines changed: 10 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -17,9 +17,9 @@ We recommend adding custom VCL configurations to a Staging environment where you
17
17
18
18
- Configure the {{ site.var.data.ece }} environment for Fastly services. See [Set up Fastly]({{ site.baseurl }}/cloud/cdn/configure-fastly.html).
19
19
20
-
-Get Admin credentials for your {{ site.data.var.ece }} environment.
20
+
- Admin credentials to access the Magento Admin UI for your {{ site.data.var.ece }} environment
21
21
22
-
- Review your site logs for fake referral URLs and make a list of domains to block.
22
+
- Review your site logs for fake referral URLs, and make a list of domains to block.
23
23
24
24
## Create a referrer block list
25
25
@@ -59,43 +59,41 @@ For more information about Edge Dictionaries, see [Creating and using Edge Dicti
59
59
60
60
## Create a custom VCL snippet to block referrer spam
61
61
62
-
The following custom VCL snippet code (JSON format) checks incoming requests and blocks requests from any referrer site included in the `referrer_blocklist`edge dictionary.
62
+
The following custom VCL snippet code (JSON format) shows the logic to check and block requests. The VCL snippet captures the host of a referrer website into a header, and then compares the host name to the list of URLs in the `referrer_blocklist` dictionary. If the host name matches, the request is blocked with a `403 Forbidden` error.
Review the example code and change values as needed:
74
+
Before creating a snippet based on this example, review the values to determine whether you need to make any changes:
75
75
76
76
-`name` — Name for the VCL snippet. For this example, we used `block_bad_referrer`.
77
77
78
78
-`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.
79
79
80
-
-`priority` — Determines when the VCL snippet runs. The priority is `5` to run this snippet code before any of the default Magento VCL snippets (`magentomodule_*`) assigned a priority of 50.
80
+
-`priority` — Determines when the VCL snippet runs. The priority is `5` to run this snippet code before any of the default Magento VCL snippets (`magentomodule_*`) assigned a priority of 50. You must set the priority for each custom snippet higher or lower than 50 depending on when you want your snippet to run. Snippets with lower priority numbers run first.
81
81
82
82
-`type` — Specifies a location to insert the snippet in the VCL version. In this example, the VCL snippet is a `recv` snippet. When the snippet is inserted into the VCL version, it is added to the `vcl_recv` subroutine, below the default Fastly VCL code and above any objects.
83
83
84
84
-`content` — The snippet of VCL code to run in one line, without line breaks.
85
85
86
-
In this example, the VCL code logic captures the host of a referrer website into a header, and then compares the host name to the list of URLs in the `referrer_blocklist` dictionary.
86
+
After reviewing and updating the code for your environment, use either of the following methods to add the custom VCL snippet to your Fastly service configuration:
87
87
88
-
If the host name matches, the request is blocked with a `403 Forbidden` error.
88
+
-[Add the custom VCL snippet from the Magento Admin](#add-the-custom-vcl-snippet). This method is recommended if you can access the Magento Admin UI. (Requires [Fastly version 1.2.58]({{site.baseurl}}/cloud/cdn/configure-fastly.html#upgrade) or later.)
89
89
90
-
See the [Fastly VCL reference](https://docs.fastly.com/vcl/reference/) for information about creating Fastly VCL code snippets.
91
-
92
-
Add the custom VCL snippet to your Fastly service configuration from the Magento 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]({{ site.baseurl }}/cloud/cdn/cloud-vcl-custom-snippets.html(#manage-custom-vcl-snippets-using-the-api).
90
+
- Save the JSON code example to a file (for example, `allowlist.json`) and [upload it using the Fastly API]({{site.baseurl}}/cloud/cdn/cloud-vcl-custom-snippets.html#manage-custom-vcl-snippets-using-the-api). Use this method if you cannot access the Magento Admin UI.
Copy file name to clipboardExpand all lines: src/cloud/cdn/fastly-vcl-blocking.md
+49-11Lines changed: 49 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ You can use the Fastly CDN module for Magento 2 to create an Edge ACL with a lis
15
15
**Prerequisites:**
16
16
17
17
- List of client IP addresses to block
18
-
-Account access and URL for the Magento Admin UI for the Staging or Production environment
18
+
-Admin credentials to access the Magento Admin UI for your {{ site.data.var.ece }} environment
19
19
- Fastly API credentials for Staging and Production environments
20
20
21
21
## Create Edge ACL for blocking client IPs {#edge-acl}
@@ -31,16 +31,16 @@ If you want to manage access for both Staging and Production sites, create the E
31
31
1. Enter IP address values in the list. Any client IPs added to this list will be blocked access from the site.
32
32
1. Optionally, select the **Negated** checkbox if needed.
33
33
34
-
You will reference the Edge ACL by name in your VCL snippet code.
34
+
You reference the Edge ACL by name in your VCL snippet code.
35
35
36
-
## Create blocklist.json {#vcl}
36
+
## Create the custom VCL for the block list {#vcl}
37
37
38
38
{:.bs-callout-info}
39
-
This example shows advanced users how to create custom VCL code snippet to configure blocking rules that can be uploaded to the Fastly service using the Fastly API. You can also configure a blocklist or allowlist from the {{ site.data.var.ee }} Admin UI. See [Blocking](https://github.com/fastly/fastly-magento2/blob/master/Documentation/Guides/BLOCKING.md) in the Fastly CDN for Magento 2 module documentation.
39
+
This example shows advanced users how to create a VCL code snippet to configure custom blocking rules that can be uploaded to the Fastly service. You can configure a block list or allow list based on country from the {{ site.data.var.ee }} Admin UI using the [Blocking](https://github.com/fastly/fastly-magento2/blob/master/Documentation/Guides/BLOCKING.md)feature available in the Fastly CDN for Magento 2 module.
40
40
41
41
After you define the Edge ACL, you can use it to create the VCL snippet to block access to the IP addresses specified in the ACL. You can use the same VCL snippet in both Staging and Production environments, but you must upload the snippet to each environment separately.
42
42
43
-
Create a `blocklist.json` file with the following VCL code in JSON format:
43
+
The following custom VCL snippet code (JSON format) shows the logic to block incoming requests with a client IP address that matches an address in the blocklist ACL.
44
44
45
45
```json
46
46
{
@@ -52,24 +52,62 @@ Create a `blocklist.json` file with the following VCL code in JSON format:
52
52
}
53
53
```
54
54
55
-
Review the following parameter values and update your code snippet if necessary:
55
+
Before creating a snippet based on this example, review the values to determine whether you need to make any changes:
56
56
57
57
-`name`: Name for the VCL snippet. For this example, we used the name `blocklist`.
58
-
-`priority`: Determines the VCL snippet call order. Set the priority to 5 to immediately run and check for blocked IP addresses. This priority runs before any of the uploaded and default Magento VCL snippets (`magentomodule_`) that have a priority of 50.
58
+
59
+
-`priority`: Determines when the VCL snippet runs. The priority is `5` to immediately run and check whether a Magento Admin UI requests are coming from an allowed IP address. The snippet runs before any of the default Magento VCL snippets (`magentomodule_*`) assigned a priority of 50. You must set the priority for each custom snippet higher or lower than 50 depending on when you want your snippet to run. Snippets with lower priority numbers run first.
60
+
59
61
-`type`: Specifies the type of VCL snippet that determines the location of the snippet in the generated VCL code. In this example, we use `recv`, which inserts the VCL code in the `vcl_recv` subroutine, below the boilerplate VCL and above any objects. See the [Fastly VCL snippet reference](https://docs.fastly.com/api/config#api-section-snippet) for the list of snippet types.
62
+
60
63
-`content`: The snippet of VCL code to run, which checks the client IP address. If the IP is in the Edge ACL, it is blocked from access with a `403 Forbidden` error for the entire website. All other client IP addresses are allowed access.
61
64
62
-
{:.bs-callout-info}
63
-
The default VCL snippets include a prepended name of `magentomodule_` with a priority of 50. **Do not use the `magentomodule_` name** for your custom VCL Snippets. You must also set the priority for each custom snippet higher or lower than 50 depending on when you want your snippet to run. Lower priority numbers execute first.
65
+
After reviewing and updating the code for your environment, use either of the following methods to add the custom VCL snippet to your Fastly service configuration:
66
+
67
+
-[Add the custom VCL snippet from the Magento Admin](#add-the-custom-vcl-snippet). This method is recommended if you can access the Magento Admin UI. (Requires [Fastly version 1.2.58]({{site.baseurl}}/cloud/cdn/configure-fastly.html#upgrade) or later.)
68
+
69
+
- Save the JSON code example to a file (for example, `blocklist.json`) and [upload it using the Fastly API]({{site.baseurl}}/cloud/cdn/cloud-vcl-custom-snippets.html#manage-custom-vcl-snippets-using-the-api). Use this method if you cannot access the Magento Admin UI.
After saving the VCL snippet, add the VCL snippet to the Fastly service configuration. See [Add VCL snippets using the Fastly API]({{ site.baseurl }}/cloud/cdn/cloud-vcl-custom-snippets.html#add-vcl-snippets-using-the-fastly-api).
81
+
1. Add the VCL snippet values:
82
+
83
+
-**Name** — `blocklist`
84
+
85
+
-**Type** — `recv`
86
+
87
+
-**Priority** — `5`
88
+
89
+
- Add the **VCL** snippet content:
90
+
91
+
```conf
92
+
if ( client.ip ~ blocklist) { error 403 "Forbidden"; }
93
+
```
94
+
95
+
1. Click **Create** to generate the VCL snippet file with the name pattern `type_priority_name.vcl`, for example `recv_5_blocklist.vcl`
96
+
97
+
1. After the page reloads, click **Upload VCL to Fastly** in the *Fastly Configuration* section to add the file to the Fastly service configuration.
98
+
99
+
1. After the uploads, refresh the cache according to the notification at the top of the page.
100
+
101
+
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.
68
102
69
103
## Additional VCL examples for blocking requests
70
104
71
105
The following examples show how to block requests using inline condition statements instead of an ACL list.
72
106
107
+
{: .bs-callout-warning}
108
+
In these examples, the VCL code is formatted as a JSON payload that can be saved to a file and submitted in a Fastly API request. You can submit the [VCL snippet from the Admin UI](#add-the-custom-vcl-snippet), or as a JSON string using the Fastly API. If you use the Fastly API with a JSON string, you must use a backslash to escape special characters to prevent validation errors.
109
+
See [Using dynamic VCL snippets](https://docs.fastly.com/vcl/vcl-snippets/) in the Fastly VCL documentation.
110
+
73
111
### VCL code sample: Block by country code
74
112
75
113
This example uses the two-character ISO 3166-1 country code for the country associated with the IP address.
0 commit comments