Varnish is an HTTP accelerator and caching layer that sits in front of your web server to dramatically improve performance.
Enable Varnish during the initial setup:
dev setupIf you've already set up your environment, enable Varnish by creating the VCL configuration file:
cp build/dist/varnish/default.vcl conf/varnish.vcl
dev rebuildVarnish uses VCL (Varnish Configuration Language) to define caching behavior. The default configuration file is located at conf/varnish.vcl.
Set the cache size via environment variable in your .env file:
CACHE_SIZE=256MDefault cache size is typically 256MB.
To use a custom VCL file:
dev varnish-vcl-import /path/to/your/custom.vclTo disable Varnish VCL:
dev varnish-vcl-disableEdit the VCL configuration:
nano conf/varnish.vclAfter making changes, reload Varnish:
dev restart varnishAccess Varnish admin commands:
dev varnishadmCommon varnishadm commands:
dev exec varnish varnishadm ban req.url '~' '.' # Ban all cached content
dev exec varnish varnishadm param.show # Show all parameters
dev exec varnish varnishadm ban.list # List active bansNote: Based on the user's CLAUDE.md, you can run varnishadm locally with:
dev exec varnish varnishadmFor Magento 2, you'll need a Magento-specific VCL. Example configuration in conf/varnish.vcl:
- Generate Magento's VCL:
dev console bin/magento varnish:vcl:generate > conf/varnish.vcl- Restart Varnish:
dev restart varnish- Configure Magento to use Varnish:
- Stores > Configuration > Advanced > System > Full Page Cache
- Set Caching Application to "Varnish Cache"
- Set Varnish host to
varnish
Check if Varnish is caching:
curl -I http://your-project.localhostLook for the X-Varnish header in the response. If present, Varnish is working.
To see if a response is cached:
X-Cache: HIT= Served from cacheX-Cache: MISS= Not in cache, fetching from backend
Check Varnish status:
dev ps | grep varnishView Varnish logs:
dev logs varnishVerify VCL syntax before restarting:
dev exec varnish varnishadm vcl.load test /etc/varnish/default.vcl