eZ Publish 5 being built on top of Symfony 2, it uses standard HTTP cache headers. By default the Symfony 2 reverse proxy, written in PHP, is used to handle cache, but it can be easily replaced with any other reverse proxy like Varnish.
Use of Varnish is a requirement for use in Clustering setup, for overview of clustering feature see Clustering.
Version compatibility: 5.4 / 2014.11 AND HIGHER
To use Varnish with 5.2 or 5.3, please see Using Varnish with eZ Publish 5.2-5.3
Prerequisites
- A working Varnish 3 or Varnish 4 setup.
Recommended VCL base files
For Varnish to work properly with eZ, you'll need to use one of the provided files as a basis:
Note: Http cache management is done with the help of FOSHttpCacheBundle. One may need to tweak their VCL further on according to FOSHttpCache documentation in order to use features supported by it.
Configure eZ Publish
Update your Virtual Host
On apache:
<VirtualHost *:80> # Configure your VirtualHost with rewrite rules and stuff # Force front controller NOT to use built-in reverse proxy. SetEnv USE_HTTP_CACHE 0 # Configure IP of your Varnish server to be trusted proxy # Replace fake IP address below by your Varnish IP address SetEnv TRUSTED_PROXIES "193.22.44.22" </VirtualHost> |
On nginx:
fastcgi_param USE_HTTP_CACHE 0; # Configure IP of your Varnish server to be trusted proxy # Replace fake IP address below by your Varnish IP address fastcgi_param TRUSTED_PROXIES "193.22.44.22" ; |
Update YML configuration
ezpublish: http_cache: # As of 5.4 only use "http" # "single_http" and "multiple_http" are deprecated but will still work. purge_type: http system: # Assuming that my_siteaccess_group your frontend AND backend siteaccesses my_siteaccess_group: http_cache: # Fill in your Varnish server(s) address(es). purge_servers: [http: //my.varnish.server:6081] |
6 Comments
Carlos Revillo
Shouldn't we maitain following if from the varnish default.vcl in our ezpublish.vcl?
https://www.varnish-cache.org/trac/browser/bin/varnishd/default.vcl?rev=3.0#L59
If removed, i have problems with post requests, example, sending data in a contact form...
Carlos Revillo
Out of scope of ez5 itself, but if you need to install Varnish Curl Vmod, there is a good tutorial here (for Debian)
http://lassekarstensen.wordpress.com/2013/07/29/building-a-varnish-vmod-on-debian/
It uses another module but the process is the same for all modules.
Jérôme Vieilledent
Carlos: Thanks. I just added this link to the page as an example for Debian.
Peter Keung
This doc page should mention that the Apache environment variable TRUSTED_PROXIES should be set if your Varnish install(s) sits on a different server. Otherwise you will get a nasty surprise when ESI breaks.
André Rømcke
Peter: Added, thanks!
Mauricio Sánchez
It is possible to use Basic HTTP Authentication in the cache invalidation request?
i. e: