Setting up Varnish full-page cache for Magento Open Source

A planning and setup guide for putting Varnish in front of a self-hosted Magento Open Source store: VCL export, purge hosts, invalidation triggers and the hit rate checks that prove it works.

On this page

Why a self-hosted Magento Open Source store needs Varnish set up deliberately

Without a full-page cache, a self-managed Magento Open Source store rebuilds anonymous category and product pages on every request, and that load lands on PHP, the database and the page-building stack. Varnish is the full-page cache accelerator Adobe documents for self-managed installations, and setting it up means exporting the VCL that Magento generates, pointing Magento at your purge hosts, and verifying that anonymous pages are actually served from cache. Cloud-hosted Adobe Commerce uses Fastly for this layer instead, so a self-managed team owns the Varnish configuration, its upgrades and its failure modes from the first day. Adobe's configuration guide for Varnish is the starting reference for the version your release line supports.

Varnish helps most with anonymous, public pages that look the same for every visitor: category listings, product detail pages and CMS pages. The pages it must not cache are the ones that carry personal or cart state: checkout, cart, customer account pages and any response that depends on the logged-in user or the visitor's session. Errors in this boundary are the main risk. A cached cart or account page can show one shopper's data to another, which turns a performance setting into a privacy and PCI DSS scoping problem. Confirm with your team which routes Magento marks as cacheable and which it bypasses, and test those routes with a logged-in session before go-live.

Plan the Varnish layer with your security and compliance owners before you tune hit rates. The VCL, the purge host list and the network path between web nodes, Varnish and the admin must be documented, because any change to them can change what the public internet receives. Ask your implementation partner to show the exact exclusion rules for checkout and account routes, and ask how cache invalidation is triggered after catalog or content changes. Confirm the Varnish version against Adobe's system requirements for your Magento release, since Adobe lists supported combinations only.

Which Varnish configuration fits your store

Varnish runs on the same host as your web server and PHP-FPM. This is the simplest layout to build and debug, because the cache, the application and the database share one machine and one set of logs. Purge requests from Magento reach Varnish over the local network path, so the purge host is usually localhost or the loopback address. The trade-off is resource contention: cache memory, PHP workers and MySQL all compete for the same RAM and CPU, so a traffic spike can slow the whole stack at once.

  • Purge routing: Magento sends invalidation requests to the one Varnish instance, so the access control list in the VCL only needs to allow that host.
  • Sizing: Cache memory must be budgeted against PHP-FPM and MySQL on the same host, which usually means a larger server before any cache tuning.
  • Failure behavior: If Varnish stops, the web node serves pages directly from PHP, so the store slows down but stays reachable.
  • Operations: One set of logs and one restart procedure covers the stack, which reduces the number of moving parts during an incident.
  • Growth: Moving to a separate tier later means changing the purge host list and backend definitions, so plan the VCL with that change in mind.

Confirm the Varnish version against the system requirements for your exact Magento release before you install anything, because the supported Varnish version differs by release line.

How to set up Varnish step by step

This sequence takes a self-hosted Magento Open Source store from a bare nginx front end to a Varnish layer that serves anonymous pages from cache, with each step closed by a check that proves the previous step worked.

  1. Confirm the release and Varnish requirement

    Before touching any server, confirm the exact Magento Open Source release and the matching Varnish version in Adobe's system requirements for that release. The 2.4.8-p5 requirements list Varnish 8, and the 2.4.9 requirements list the supported PHP, MySQL, OpenSearch, Redis or Valkey, RabbitMQ, Composer and nginx versions, but Varnish is not listed for 2.4.9 in the facts supplied, so confirm that row against the Adobe guide for your version. Adobe supports only the listed combinations. The owner of the platform signs off on the versions. Done means a written version matrix that the team has checked against the installed release.

  2. Export the VCL from Magento configuration

    In the Magento admin, open the full-page cache settings under the cache management area and select Varnish as the caching application. Use the export option there to generate the VCL file, then confirm the exact menu path and command for your version in the Adobe configuration guide. Check the exported file: the backend host and port should point to the nginx or web node that serves PHP, not to the Varnish host itself. Done means a VCL file on disk whose backend definition matches your web node and whose ACL includes the purge hosts you plan to use.

  3. Install Varnish and load the exported VCL

    On a dedicated host or container that your team controls, install the Varnish version confirmed in the first step and load the exported VCL file as the active configuration. Record the file path and the version so the next upgrade can regenerate and compare it. Use the service commands documented for your Varnish release rather than copying them from older guides. Check that Varnish starts, that the configuration compiles without errors, and that the backend shows as healthy or reachable. Done means a running Varnish instance with a compiled VCL that points at the intended backend.

  4. Place Varnish in front of nginx

    Change the front door so that public traffic reaches Varnish on port 80 or 443 termination point your architecture uses, and Varnish forwards to nginx, which continues to serve PHP-FPM. Keep TLS termination and any load balancer decisions documented, because the client IP and protocol headers must reach Magento correctly. Confirm the nginx listen address and the proxy target in the Adobe guide for your setup. Check that a normal page loads through the new path and that Magento still sees the real client address. Done means a storefront request that flows client to Varnish to nginx to PHP and returns a correct page.

  5. Set the Varnish host and purge access list

    In the Magento admin full-page cache settings, enter the Varnish host or hosts that Magento should send purge requests to, and define the access list that permits purge requests from the Magento application servers. Keep this list as narrow as possible, and make sure the same addresses appear in the VCL access control list, since a mismatch causes purges to fail silently. Confirm the field names and any port settings in the Adobe guide for your version. Check by changing a product or CMS page in a test environment and watching for the purge in Varnish logs. Done means Magento can reach Varnish for purges and Varnish accepts them only from approved hosts.

  6. Verify cache headers on anonymous responses

    Request a public category or product page twice without logging in and inspect the response headers. Look for the cache headers that Magento and Varnish set, and confirm that the second response is served from cache by checking the Varnish hit counters or logs. Then request a logged-in customer page, the cart, and the checkout, and confirm they are not cached. If a cacheable page returns no cache header, or a private page is cached, stop and review the VCL and the cache-control settings before going further. Done means anonymous pages show hits on repeat requests and private pages always reach the backend.

  7. Confirm invalidation and track the hit rate

    Edit a product and a category in the admin, then confirm that the affected pages are purged and that the next request fetches fresh content. Record a baseline hit rate from Varnish statistics across a normal traffic period, and repeat the measurement after a warm-up. Watch for a rising miss rate after deployments, which often points to purges that are too broad or to cookies that vary responses unexpectedly. Done means invalidation works for the content types your store changes often, and the team has a recorded baseline hit rate to compare against after each release.

How a request moves through Varnish, nginx and Magento

The diagram starts with a shopper's browser sending a request to Varnish, which serves cached pages directly and passes misses to nginx and PHP-FPM running Magento. The purge path runs the other way: when a catalog or content change is saved, Magento sends invalidation requests back to the Varnish purge hosts. Check the trust boundary around the purge endpoint, and confirm that session cookies for logged-in customers and carts bypass the cache as expected.

Cache hits, cache misses and the purge path back to Varnish.

What triggers cache invalidation and what must never be cached

Invalidation decides how much of the Varnish benefit survives contact with a working store. Saving products, categories, CMS pages and configuration sends purge requests to Varnish, so each of those saves removes the affected cached pages. Treat each trigger as a separate decision: which entity types purge which pages, and whether a broad purge (for example, a category save that clears every listing page it touches) is acceptable on your catalog. Aggressive invalidation keeps content fresh but lowers the cache hit rate, because pages are rebuilt more often and the origin serves more requests. Looser invalidation raises the hit rate but risks showing shoppers stale prices, stock states or promotions. Choose the trade-off per content type, and record it so the team that edits content knows what a save will clear.

Some content must never be stored in a shared cache. Cart, checkout, customer account pages and any block that shows the logged-in customer's name, addresses or prices depend on private data. Magento handles these through private content and Edge Side Includes (ESI) style placeholders, so the cached page stays generic while personalized fragments load per visitor. Confirm in the VCL you export that session and customer cookies bypass the cache, that the private content cookies are passed through, and that no custom block, module or theme template renders personal data outside those placeholders. A custom extension that adds a personalized widget to a category page is a common source of leaked content, so review extensions against this list before launch.

Test every invalidation trigger on your own catalog before go-live, not only on a staging copy with sample data. For each entity type you edit, save it, then request the affected pages and confirm the new content appears while unrelated pages stay cached. Measure the hit rate before and after the test, and repeat it with the real volume of product and category changes your merchandising team makes in a normal week. Ask your implementation partner or your team to document each trigger, the pages it clears and the expected hit rate per page type, so the decision is written down before peak season.

Security and operational risks of a Varnish layer

A Varnish layer in front of Magento Open Source speeds up anonymous pages, but it also changes who can reach cached content, how stale data is served and how much memory the server needs. Each card below is a risk to review before the cache goes live, with the check that shows whether it is under control.

Purge endpoint exposed to untrusted networks

Varnish accepts purge requests from the hosts you list in its access control list, and an open purge path lets anyone clear pages and degrade the cache on demand. Restrict the purge access list to the web nodes and admin hosts that need it, keep it out of public routing, and test from an outside network that a purge request is refused. Confirm how your exported VCL defines the purge hosts before go-live, since that list is the control you will review most often.

Varnish cache docs

Personalized pages cached for everyone

Varnish should only store responses that are safe to share between visitors. Cart, checkout, customer account and any page that shows a logged-in name or payment detail must bypass the cache, or one shopper's data can be served to another. Check cache headers on those routes with two separate sessions, and confirm that the session cookie is part of the bypass logic in the VCL you deploy.

Stale prices and stock after indexing

A cached product page can keep showing an old price or stock status after the underlying data has changed, if the purge did not run for that URL. Map each indexer and admin action that changes price, stock or content to a purge event, and test one change end to end: update a price, confirm the index run, then reload the cached page. Ask your team to document which changes purge only the affected URLs and which flush the whole cache.

Memory exhaustion without sizing

Varnish keeps cached objects in memory, and an undersized storage setting causes early eviction, lower hit rates and more load on PHP and the database. Size the cache storage from the number of cacheable pages, typical object size and the memory left after PHP-FPM and MySQL are allocated, then watch eviction counts after launch. Ask your hosting team how the storage limit is set in the service definition, because the default is rarely right for a large catalog.

VCL changes that skip review during upgrades

The VCL is code that controls caching, purging and bypass rules, and it can change when Magento, Varnish or a module is upgraded. Treat the exported VCL as a versioned file in your repository, review every diff before a patch cycle, and rerun the purge and bypass tests after each change. Adobe recommends applying patches every cycle to stay secure, so the VCL review belongs in that same window rather than being left for later.

How to read the cache hit rate and prove Varnish is working

The proof that Varnish is working is a measured hit rate on anonymous storefront traffic, read from Varnish's own counters and from the response headers it returns. Start with the hit and miss counters that varnishstat reports for the running instance. Confirm the exact counter names against the Varnish version you deploy, because they differ between releases and the Adobe guidance is tied to the version listed in your system requirements. Next, send the same product or category URL twice with curl -I and check the response for a cache status header that Adobe's Varnish configuration sets. A first request that reports a miss followed by a repeat that reports a hit shows the cache is storing and serving pages. Keep a small set of representative URLs in a file so every check uses the same pages.

Compare anonymous and logged-in traffic separately. Magento sends a private cookie for logged-in customers and cart contents, and Varnish should bypass or vary on those cookies rather than cache personal pages for everyone. A low hit rate on logged-in sessions is expected, while a low rate on anonymous category and product pages points to a configuration or cookie problem. Measure both populations over the same window so the numbers can be compared. A cold cache after a deployment or a Varnish restart will show many misses and a lower hit rate for a while, so do not judge the setup in that window. Record the hit rate before and after a catalog change, such as a bulk price update or a category reorganization, because each change purges affected objects and the recovery curve shows whether invalidation is scoped correctly. Ask your team to document which metric names, cookies and headers were confirmed for your version, so the baseline stays comparable after upgrades.

Questions buyers ask about Varnish for Magento

What does a Varnish setup for Magento Open Source cost?

No price is supplied for this work, and DeployOpen does not publish a price list, so the cost comes from the written scope. The main cost components are the time to export and review the VCL, configure purge hosts and cache exclusions, test invalidation on the catalog and content paths, and set up the nodes and monitoring. Ask any quote to separate one-time work (initial build, testing, documentation) from recurring work (patch-cycle retesting, VCL changes after extension updates). Ask which environments are included, such as staging and production, and how many web nodes are covered.

What drives the effort of a Varnish project?

Effort rises with how much the store departs from the default VCL. The main drivers are:

  • Custom VCL logic, such as exceptions for personalized blocks, geolocation or currency cookies
  • The number of installed extensions that set cache-related headers or block caching
  • The number of web nodes that must share purge configuration
  • The depth of testing across product, category, CMS and checkout pages

Ask the quote to list each of these as a line item so you can see which one moves the total.

How long does a Varnish implementation take?

Duration depends on scope, and no timeline is supplied for this work, so treat any figure you hear as unverified until it is written into a scope. A standard single-store setup with the default VCL moves faster than a store with custom VCL, several web nodes and extensions that alter caching. Ask for the timeline to be tied to milestones: environment access, VCL export, staging validation, load-tested cache behavior and production cutover. Also ask how the timeline accounts for your release calendar.

What does our internal team need to provide?

The work moves faster when the internal team has the following ready before the kickoff:

  • Access to the infrastructure where Varnish and the web nodes will run, including network paths to the purge hosts
  • A release calendar that shows freeze windows and planned Magento patch dates
  • Catalog and content samples, such as products with many variations, large categories and CMS pages with embedded blocks
  • A named owner for decisions on which pages may be cached and for how long

Confirm these in the scope document so delays are assigned clearly.

Can our in-house team set up Varnish for Magento alone?

Yes, a capable in-house team can do this, provided it has engineers who understand Magento's cache tags, the Varnish configuration language and the store's own caching exceptions. Adobe documents Varnish as the full-page cache accelerator for self-managed installations, so the configuration guide is the right starting point. The risks to weigh are testing gaps, such as stale personalized content reaching shoppers, and ownership after launch, when VCL needs changes with each extension update. Ask a partner to show what it would deliver that your team would not, such as a written test matrix and runbook.

How do Magento patch upgrades change the Varnish setup?

Patch upgrades can change cache behavior, so the Varnish setup should be retested each patch cycle. Adobe's upgrade guide recommends upgrading every patch cycle to stay secure and PCI compliant, and Adobe's requirements for 2.4.8-p5 list Varnish 8 among the supported components. Check that your Varnish version is on that list for your target release, then rerun purge and hit-rate checks after each upgrade. Ask whether retesting is included in the retainer or priced separately.

Does DeployOpen's Varnish work include a compliance certification?

No. DeployOpen implements and documents the Varnish setup and can prepare evidence for compliance assessments, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies carry out those assessments. If your payment scope depends on the cache layer, ask the quote to state which configuration records, test results and change logs will be delivered for your assessor.

How DeployOpen scopes and delivers a Varnish setup

DeployOpen plans, builds, tests and hands over Varnish full-page cache for Magento Open Source inside your own infrastructure, so your team can review the VCL, purge path and hit rate checks before go-live. Most engagements are fixed-scope, with the deliverables and timeline agreed in writing before work starts.

How we scope

  • Confirm which Magento Open Source release line and Varnish version your environment will run against the published requirements.
  • Map the pages, blocks and cache-sensitive customer data that the exported VCL must handle correctly.
  • Agree in writing which purge hosts, ACL addresses, invalidation triggers and verification checks are in scope.

How we build

  • Export the VCL for your store configuration and review it against your web node layout and backend addresses.
  • Configure purge hosts and access control lists so cache invalidation reaches every Varnish node you operate.
  • Test invalidation after product, category and CMS saves, and record the cache hit rate on warm and cold runs.

How we hand over

  • Deliver the versioned VCL, configuration notes and the list of invalidation triggers with their expected behavior.
  • Document the hit rate checks, the commands used to run them and the log locations that show cache behavior.
  • Walk your platform and operations team through the runbook for restarts, VCL changes and failed purges.

How we support

  • Retest the Varnish setup when you apply a Magento Open Source patch or move to a new release line.
  • Review cache behavior after changes to extensions, themes or the storefront, since these can alter cacheable responses.
  • Ongoing support, upgrades and continuous testing are available as a retainer, scoped in writing.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.