# Adobe Commerce and Magento 2 Varnish configuration, 2.4.4 to 2.4.9

**By Oleg Snegov.** Read time 11 minutes. Published Thursday, April 24, 2025.

**Tags:** Varnish, Adobe Commerce, Magento, Mage-OS, Full Page Cache, Performance

---

Magento 2 Varnish configuration comes down to four steps on Adobe Commerce, Magento Open Source and Mage-OS: run a Varnish version Adobe supports for your release, put it in front of the web server, switch the full page cache to Varnish and load the VCL that Commerce generates with `bin/magento varnish:vcl:generate`, then tell Commerce where to send purges. The steps are the same from 2.4.4 through 2.4.9; what changes by release is the Varnish version and the VCL template. On Adobe Commerce on cloud infrastructure you skip all of it, because Fastly is the full page cache in Staging and Production.

---

## Which Varnish version does Magento 2 support?

Adobe lists one supported Varnish version for each release and patch in its system requirements. For on-premises sites, as of November 2026:

| Release line | Varnish at release | Newest patch Adobe lists | VCL templates you can export |
|---|---|---|---|
| 2.4.9 | 8 | 8 | 6, 7 |
| 2.4.8 | 7.6 | 8 at 2.4.8-p5 (7.7 for p1 to p4) | 6, 7 |
| 2.4.7 | 7.5 | 8 at 2.4.7-p10 (7.7 for p6 to p9) | 6 |
| 2.4.6 | 7.1 | 8 at 2.4.6-p15 (7.7 for p11 to p14) | 4, 5, 6 |
| 2.4.5 | 7.0 | 8 at 2.4.5-p17 (7.7 for p13 to p16) | 4, 5, 6 |
| 2.4.4 | 7.0 | 7.7 (p14 to p18) | 4, 5, 6 |

Three things the table doesn't say out loud:

- **The template number isn't your Varnish version.** `varnish6.vcl` says its minimum is Varnish 6.0 and `varnish7.vcl` says 7.0. On 2.4.7 and earlier, the 6 template is the newest you can export, including on patches where Adobe lists Varnish 7.x or 8.
- **There's no `varnish8.vcl`.** Adobe lists Varnish 8 for 2.4.9 and for the newest patches of 2.4.5 through 2.4.8, but the newest template is still the 7 export. Compile-check whatever you export against the Varnish you actually run before it takes traffic.
- **2.4.7 dropped Varnish 4 and 5.** The export no longer offers them, so if a runbook still says `--export-version=4` or `5`, it was written for an older site.

Mage-OS uses the same PageCache module and the same commands. Mage-OS 3.x and 4.0 are built on Magento Open Source 2.4.9 and Mage-OS 2.x on 2.4.8, so pick the template for that base. Mage-OS's own requirements page recommends Varnish 7.7.

---

## How do I configure Varnish with nginx for Magento 2?

Varnish speaks plain HTTP. Adobe's docs say it directly, "Varnish does not support SSL", and recommend an SSL termination proxy in front of it, such as nginx. A single-server setup usually looks like this:

| Port | What listens | What it does |
|---|---|---|
| 443 | nginx (TLS) | Ends HTTPS and passes the request to Varnish |
| 80 | Varnish | Answers cache hits, sends misses to the backend |
| 8080 | nginx or Apache running Commerce | Runs PHP and Commerce |

1. Install Varnish from your OS packages or Varnish's own repository, then check the version with `varnishd -V`. Adobe asks you to confirm it's a supported version before you go further.
2. Move the Commerce web server to port 8080: the `listen` directive of the Commerce server block in nginx, or `Listen 8080` and the virtual host in Apache.
3. Make Varnish listen on port 80. Where that's set depends on your packaging: a systemd unit, `/etc/default/varnish` or `/etc/varnish/varnish.params`.
4. Put TLS in front and tell Commerce the original request was HTTPS:

```
server {
    listen 443 ssl;
    server_name shop.example.com;
    # ssl_certificate and ssl_certificate_key go here

    location / {
        proxy_pass http://127.0.0.1:80;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
```

`X-Forwarded-Proto` isn't decoration. It's the default value of Commerce's **Offloader header** setting (Stores > Settings > Configuration > General > Web > Base URLs (Secure)), which is how Commerce knows the shopper is on HTTPS. The generated VCL also adds that header to the cache key, so the HTTP and HTTPS copies of a page never mix.

---

## How do I generate the Varnish VCL for Magento 2?

In the Admin, open **Stores > Settings > Configuration > Advanced > System > Full Page Cache**:

1. Set **Caching Application** to **Varnish Caching**.
2. Leave **TTL for public content** at 86400 seconds (one day) unless you have a reason to change it. Product, category and price changes purge the affected pages anyway.
3. Under **Varnish Configuration**, fill in **Access list** (who may purge), **Backend host** and **Backend port** (your web server, for example 127.0.0.1 and 8080) and **Grace period** (300 seconds by default).
4. Save, then click **Export VCL for Varnish 7** on 2.4.8 and 2.4.9, or **Export VCL for Varnish 6** on earlier releases.

From 2.4.7 you'll also see **Handles params size** (default 100). It caps how many layout handles the `page_cache/block/esi` endpoint will process.

The same from the command line:

```
bin/magento config:set --scope=default --scope-code=0 system/full_page_cache/caching_application 2

bin/magento varnish:vcl:generate \
  --export-version=7 \
  --access-list=127.0.0.1 \
  --backend-host=127.0.0.1 \
  --backend-port=8080 \
  --grace-period=300 \
  --output-file=/tmp/default.vcl
```

`caching_application` is `1` for the built-in cache and `2` for Varnish. Pass all options explicitly or you'll get a VCL for localhost:8080 built from the 6 template. From 2.4.7, `--input-file` builds the VCL from your own template so your changes can live in git.

Install it as root, compile-check and restart:

```
cp /etc/varnish/default.vcl /etc/varnish/default.vcl.bak
cp /tmp/default.vcl /etc/varnish/default.vcl
varnishd -C -f /etc/varnish/default.vcl > /dev/null && systemctl restart varnish
```

Read two parts of the file before you restart:

- **`acl purge`** must list the addresses PURGE requests come from (the server(s) running Commerce). A PURGE from anywhere else gets `405 Method not allowed`.
- **The health probe's `.url`.** Templates from 2.4.7 on probe `/health_check.php`; older templates probe `/pub/health_check.php`. A probe 404 marks the backend sick and causes 503s.

---

## How does Commerce tell Varnish to purge?

Commerce purges Varnish automatically when you change products, categories, prices and promotional pricing rules, and when you clean or flush the cache. It just needs to know where Varnish is:

```
bin/magento setup:config:set --http-cache-hosts=127.0.0.1:80
```

List every Varnish host, comma-separated with no spaces: `--http-cache-hosts=10.0.0.21:80,10.0.0.22:80`.

---

## How do I check that Varnish is caching Magento pages?

Request the same page twice and read the headers:

```
curl -sI https://shop.example.com/ | grep -i -E 'x-magento-cache-debug|grace'
curl -sI https://shop.example.com/ | grep -i -E 'x-magento-cache-debug|grace'
```

The Commerce VCL sets `X-Magento-Cache-Debug` on every response: `MISS` the first time, `HIT` after that, and from 2.4.7 `UNCACHEABLE` when the response couldn't be cached at all.

What you won't see is `X-Varnish`, `Via` or `Server` — the Commerce VCL removes them. An empty `grep X-Varnish` doesn't mean Varnish is off.

Three more checks:

- **`var/page_cache` stays empty** while you browse cacheable pages. Files there mean Commerce is still using the built-in cache.
- **Cacheable pages load fast.** Adobe's figure: a page with cacheable blocks should load in under 150 ms when Varnish serves it.
- **Hits outnumber misses.** `varnishstat -1 -f MAIN.cache_hit -f MAIN.cache_miss` shows both counters since Varnish started.

---

## Why does Varnish return 503 Backend fetch failed?

Adobe documents two causes.

**The cache-tags header is too long.** Commerce lists every product and category on a page in an `X-Magento-Tags` response header, and Varnish's default `http_resp_hdr_len` is 8 KB. Adobe's fix is to set it to your largest category's product count times 21, for example 65536 bytes for a category of about 3,000 products, and raise `http_resp_size` and `workspace_backend` to match:

```
-p http_resp_hdr_len=65536 \
-p http_resp_size=98304 \
-p workspace_backend=98304 \
```

These are `varnishd` startup parameters, not VCL.

**The backend is slow or marked sick.** The generated VCL already sets `.first_byte_timeout = 600s`. If you hand-wrote your backend block, add it. Check the health probe: `varnishadm backend.list` shows whether Varnish thinks the backend is healthy.

---

## Why isn't Varnish clearing the cache?

Work through these in order:

- **No `http_cache_hosts`.** This is the most common cause. See the purge section above.
- **The PURGE is rejected.** Send one by hand from the Commerce server: `curl -X PURGE -H 'X-Magento-Tags-Pattern: .*' http://127.0.0.1:80/`. `200 Purged` is good; `405` means the sender isn't in `acl purge`; `400` means the header is missing.
- **You cleaned the wrong cache type.** Since 2.4.7, `bin/magento cache:clean config` or `cache:clean layout` no longer purges the full page cache. Run `bin/magento cache:clean full_page`, or `cache:clean` with no types.
- **The change hasn't been written yet.** Admin mass attribute updates are saved by the `product_action_attribute.update` queue consumer, so if consumers aren't running there's nothing to purge yet.
- **A module doesn't tag its pages.** A block that shows data from its own tables needs its own cache tags, or Commerce can't know which pages to purge when that data changes.

Two things not to do: `rm -rf var/page_cache/*` does nothing for Varnish (that directory belongs to the built-in cache). And restarting Varnish to clear it empties the whole cache and sends every request to PHP at once.

---

## Is anything on your pages getting past Varnish?

The Commerce VCL passes anything that isn't GET or HEAD, plus URLs under `/customer` and `/checkout`. If product or category pages come back `UNCACHEABLE`, look first for a block with `cacheable="false"` in layout XML: one such block makes the whole page uncacheable.

---

## What about Varnish on Adobe Commerce Cloud?

On Adobe Commerce on cloud infrastructure, you don't install or configure Varnish. Fastly, a Varnish-based CDN, is the full page cache and is required in Staging and Production. Integration environments don't have it. You set **Caching Application** to **Fastly CDN**, upload the Fastly VCL from the Admin, and make changes with Fastly custom VCL snippets rather than a `default.vcl`. To check it's working:

```
curl https://shop.example.com -vo /dev/null -H Fastly-Debug:1
```

Look for `Fastly-Magento-VCL-Uploaded` and `X-Cache` with a `HIT` in the response.

---

## Frequently asked questions

### Which VCL should I export for Varnish 7 or 8?

On 2.4.8 and 2.4.9, export version 7 (`--export-version=7`, or **Export VCL for Varnish 7** in the Admin). On 2.4.7 and earlier, version 6 is the newest template there is. There's no Varnish 8 template on any release, so compile-check the export with `varnishd -C -f` on the Varnish you run.

### Does Varnish cache GraphQL requests?

Yes, GET queries only. Adobe's GraphQL caching docs say POST queries aren't cached, mutations must be POST, and a request that includes cart, customer, order or wishlist data skips the cache. Since 2.4.4 the `X-Magento-Cache-Id` header lets Varnish or Fastly cache results for logged-in customers, keyed on store, currency, customer group and tax rate.

### Should Varnish cache static files?

Not by default. The Commerce VCL passes `/static` and `/media` straight to the web server. Adobe recommends a CDN for assets, and says caching them in Varnish can pay off when you serve few locales and your customers are near your servers. If you turn it on, restart Varnish after every deploy that changes assets.

### Can I edit the generated default.vcl?

Yes, but every export overwrites it and upgrades change the template. 2.4.8 strips more marketing parameters from URLs (`gad_source`, `srsltid` and `msclkid` among them), and 2.4.9 sorts query strings so the same page isn't cached twice. From 2.4.7, keep your version in git, build from it with `--input-file`, and diff it against the new template on every upgrade.

### Do I still need Redis if I run Varnish?

Yes, for a different job. Varnish holds pages. Redis, or Valkey on 2.4.9 and the newest patches, holds Commerce's own cache (configuration, layout, blocks) and sessions.

### Is Varnish configured differently on Mage-OS?

No. Mage-OS ships the same PageCache module and the same `bin/magento` commands, so everything here applies. Match the template to the Magento Open Source release your Mage-OS version is built on: 2.4.9 for Mage-OS 3.x and 4.0, 2.4.8 for Mage-OS 2.x.
