Message-ID: <624808228.4282.1485862245592.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_4281_1804979655.1485862245592" ------=_Part_4281_1804979655.1485862245592 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Using Varnish

Using Varnish

eZ Publish 5 being built on top of Symfony 2, it uses standard H= TTP 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 rever= se proxy like Varnish.

Configure Varnish

Provided VCL example is given for Varnish 3.x only

The first thing is to configure Varnish to advertise ESI usage and to ac= tivate cache invalidation:

ezpublish5.vcl
=20
# Varnish 3.x - eZ Publish 5 - Complete VCL
 
# Our Backend - We assume that eZ Publish Web server listen on port 80
backend ezpublish {
    .host =3D "127.0.0.1";
    .port =3D "80";
}
=20
# ACL for purgers IP.
# Provide here IP addresses that are allowed to send PURGE requests.
# PURGE requests will be sent by the backend.
acl purgers {
    "127.0.0.1";
    "192.168.0.0"/16;
}
=20
# Called at the beginning of a request, after the complete request has been=
 received
sub vcl_recv {
=20
    # Set the backend
    set req.backend =3D ezpublish;
=20
    # Advertise Symfony for ESI support
    set req.http.Surrogate-Capability =3D "abc=3DESI/1.0";
=20
    # Add a unique header containing the client address (only for master re=
quest)
    # Please note that /_fragment URI can change in Symfony configuration
    if (!req.url ~ "^/_fragment") {
        if (req.http.x-forwarded-for) {
            set req.http.X-Forwarded-For =3D req.http.X-Forwarded-For + ", =
" + client.ip;
        } else {
            set req.http.X-Forwarded-For =3D client.ip;
        }
    }
=20
    # Handle purge
    # Only works with "multiple_http" purge method
    if (req.request =3D=3D "PURGE") {
        if (!client.ip ~ purgers) {
            error 405 "Method not allowed";
        }
 
        if ( req.http.X-Location-Id =3D=3D "*" ) {
            # Purge all locations
            ban( "obj.http.X-Location-Id ~ ^[0-9]+$" );
            error 200 "Purge all locations done.";
        } elseif ( req.http.X-Location-Id ) {
            # Purge location by its locationId
            ban( "obj.http.X-Location-Id =3D=3D " + req.http.X-Location-Id =
);
            error 200 "Purge of content connected to the location id(" + re=
q.http.X-Location-Id + ") done.";
        }
    }
=20
    # Normalize the Accept-Encoding headers
    if (req.http.Accept-Encoding) {
        if (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding =3D "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate") {
            set req.http.Accept-Encoding =3D "deflate";
        } else {
            unset req.http.Accept-Encoding;
        }
    }
=20
    # Don't cache Authenticate & Authorization
    if (req.http.Authenticate || req.http.Authorization) {
        return(pass);
    }
 
    # Don't cache requests other than GET and HEAD.
    if (req.request !=3D "GET" && req.request !=3D "HEAD") {
        return (pass);
    }
=20
    # Don't cache authenticated sessions
    if (req.http.Cookie && req.http.Cookie ~ "is_logged_in=3D" ) {
        return(pass);
    }
=20
    # If it passes all these tests, do a lookup anyway;
    return (lookup);
}
=20
# Called when the requested object has been retrieved from the backend
sub vcl_fetch {
=20
    # Optimize to only parse the Response contents from Symfony
    if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
        unset beresp.http.Surrogate-Control;
        set beresp.do_esi =3D true;
    }
=20
    # Don't cache response with Set-Cookie
    if ( beresp.http.Set-Cookie ) {
        set beresp.ttl =3D 0s;
        return (hit_for_pass);
    }
=20
    # Respect the Cache-Control=3Dprivate header from the backend
    if (beresp.http.Cache-Control ~ "private") {
        set beresp.ttl =3D 0s;
        return (hit_for_pass);
    }
=20
    return (deliver);
}

=20

You can of course add additional rules if you need.

Configure eZ Publish

Update your front control= ler

By default your front controller (index.php) uses the built= -in reverse proxy, EzPublishCache. In order to use Varnish, yo= u need to deactivate it by commenting the line where EzPublishCache is instantiated:

=20
<?php
// ...
require_once __DIR__ . '/../ezpublish/EzPublishKernel.php';
require_once __DIR__ . '/../ezpublish/EzPublishCache.php';
$kernel =3D new EzPublishKernel( 'prod', false );
$kernel->loadClassCache();
// Comment the following line if you use an external reverse proxy (e.g. Va=
rnish)
// $kernel =3D new EzPublishCache( $kernel );
$request =3D Request::createFromGlobals();
// Uncomment the following if your application is behind a reverse proxy yo=
u manage and trust.
// (see http://fabien.potencier.org/article/51/create-your-own-framework-on=
-top-of-the-symfony2-components-part-2)
//Request::trustProxyData();
$response =3D $kernel->handle( $request );
$response->send();
$kernel->terminate( $request, $response );
=20

 

Update YML configuration
ezpublish.yml
=20
ezpublish:
    http_cache:
        # Use multiple_http method for purging content
        purge_type: multiple_http
 
    system:
        # Assuming that my_siteaccess_group your frontend AND backend sitea=
ccesses
        my_siteaccess_group:
            http_cache:
                # Fill in your Varnish server(s) address(es).
                purge_servers: [http://my.varnish.server:6081]
=20

Et voil=C3=A0 !

------=_Part_4281_1804979655.1485862245592--