Skip to content

Commit 87f0ab9

Browse files
authored
Merge pull request #294 from ByteInternet/update_magento2_varnish_doc
docs/magento2: Update Varnish documentation
2 parents 44857e8 + b2567c5 commit 87f0ab9

File tree

1 file changed

+16
-52
lines changed

1 file changed

+16
-52
lines changed

docs/ecommerce-applications/magento-2/how-to-configure-varnish-for-magento-2-x.md

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $ hypernode-systemctl settings varnish_version 7.x
2929
**Enable Varnish via the [hypernode-systemctl tool](../../hypernode-platform/tools/how-to-use-the-hypernode-systemctl-cli-tool.md)**
3030

3131
```console
32-
$ hypernode-systemctl settings varnish_enabled true
32+
$ hypernode-systemctl settings varnish_enabled True
3333
```
3434

3535
**Enable Varnish via the [Control Panel](https://auth.hypernode.com/)**
@@ -49,64 +49,30 @@ $ hypernode-manage-vhosts EXAMPLE.COM --varnish
4949

5050
## Configure Magento 2.x for Varnish
5151

52-
- Log in to the Magento Admin/Backend as an administrator.
53-
- Navigate to **Stores > Configuration > Advanced > System > Full Page Cache**
54-
- From the **Caching Application** list, click `Varnish Caching`
55-
- Enter a TTL value
56-
- Expand Varnish Configuration and insert the correct information:
57-
- `Backend Host`: 127.0.0.1
58-
- `Backend Port`: 8080
59-
- Save your VCL by clicking the button **`Save config`** in the top right
60-
- Click *Export VCL for Varnish 4 or *Export VCL for Varnish 6**
52+
### Configure Magento to use Varnish
6153

62-
### Configure Your Backend Servers Through the Commandline
63-
64-
If you want to flush the Varnish cache from the Magento backend, you need to add the Varnish server in your Magento config to `http-cache-hosts`.
65-
66-
To do this, run the following command:
54+
The first step is to configure Magento to make use of the Varnish caching backend and to know which Varnish port needs to be used when flushing the cache.
6755

6856
```console
6957
$ cd /data/web/magento2
58+
$ bin/magento config:set system/full_page_cache/caching_application 2
7059
$ bin/magento setup:config:set --http-cache-hosts=varnish:6081
7160
```
7261

73-
Now when you flush your caches in cache management, your varnish full_page cache will be flushed too.
74-
75-
### Test and Upload Your VCL
76-
77-
After downloading your VCL, check (in notepad or something similar) if the following configuration is present:
78-
79-
```vcl
80-
backend default {
81-
.host = "127.0.0.1";
82-
.port = "8080";
83-
}
84-
```
62+
Now when you flush your caches in cache management, your Varnish full_page cache will be flushed too.
8563

86-
If your VCL checks out, upload it to your Hypernode (using SCP, FTP or FTPS or whichever client you prefer)
64+
### Generating the VCL
8765

88-
#### Remove Health Check Probe from Configuration
66+
Run the following commands to generate the VCL configuration from Magento. The second command will remove the health check probe, which is not needed for full-page caching.
8967

90-
**Note:** The default VCL might have the following configuration:
68+
In this example, we pass the option `--export-version=6`, change the version number to the Varnish version you're using. As of writing, the following options are supported: 4, 5 and 6. If you're using Varnish 7, you can go with `--export-version=6`.
9169

92-
```vcl
93-
backend default {
94-
.host = "localhost";
95-
.port = "8080";
96-
.first_byte_timeout = 600s;
97-
.probe = {
98-
.url = "/pub/health_check.php";
99-
.timeout = 2s;
100-
.interval = 5s;
101-
.window = 10;
102-
.threshold = 5;
103-
}
104-
}
70+
```console
71+
$ bin/magento varnish:vcl:generate --export-version=6 --backend-host="127.0.0.1" --access-list localhost > /data/web/magento2.vcl
72+
$ sed -i -E '/[[:space:]]*\.probe[[:space:]]*=[[:space:]]*\{/,/[[:space:]]*}/d' /data/web/magento2.vcl
10573
```
10674

107-
Make sure you change this to the aforementioned configuration (without the health_check probe), since this will break on our Nginx configuration and will therefore result in a `503 Guru Meditation` error.
108-
109-
**Note:** If you are using a cluster setup, you need to add some additional configuration to your vcl.
75+
**Note:** If you are using a cluster setup, you need to add some additional configuration to your VCL.
11076
The `acl purge` block inside your vcl should contain the private ip range of your cluster.
11177
You can find your private ip range using the `hypernode-cluster-info` command on one of your cluster nodes.
11278

@@ -122,23 +88,21 @@ acl purge {
12288

12389
## Import Your VCL into the Varnish Daemon
12490

125-
Import your VCL into Varnish and save as `mag2`:
91+
Import your VCL into Varnish and save as `magento2`:
12692

12793
```console
128-
$ varnishadm vcl.load mag2 /data/web/default.vcl
129-
94+
$ varnishadm vcl.load magento2 /data/web/magento2.vcl
13095
```
13196

13297
The output should say: *your VCL is compiled*. If you receive a `Permission denied` error, and have recently activated Varnish, please close all ssh sessions, and log back in to reload your new permissions.
13398

13499
Now tell Varnish to activate the loaded VCL:
135100

136101
```console
137-
$ varnishadm vcl.use mag2
138-
102+
$ varnishadm vcl.use magento2
139103
```
140104

141-
In the examples we used the name ‘mag2’ for our VCL, but you can use any name you prefer.
105+
In the examples we used the name ‘magento2’ for our VCL, but you can use any name you prefer.
142106

143107
### Test if the Correct VCL is Uploaded
144108

0 commit comments

Comments
 (0)