diff --git a/docs/infrastructure_and_maintenance/clustering/clustering_with_ddev.md b/docs/infrastructure_and_maintenance/clustering/clustering_with_ddev.md index 49e950feaf..11257dee67 100644 --- a/docs/infrastructure_and_maintenance/clustering/clustering_with_ddev.md +++ b/docs/infrastructure_and_maintenance/clustering/clustering_with_ddev.md @@ -27,6 +27,129 @@ The `ddev config --php-version` option should set the same PHP version as the pr To run an [[= product_name_cloud =]] project locally, you may refer to [DDEV and Ibexa Cloud](ddev_and_ibexa_cloud.md) instead. +## Install reverse proxy + +A reverse proxy can be added to the cluster to enable [HTTP caching](http_cache.md). + +### Varnish + +The following sequence of commands: + +1. Sets a variable with the desired Varnish version, here Varnish 7.1 +2. Copies and customizes `parameters.vcl` file in `.ddev/varnish/` (which is mounted as `/etc/varnish/` into the container): + - sets `web` container as the backend host and an invalidator (so back office can purge cache) + - adds "all IPs" CIDR notation to `debuggers` list to allow debugging from any IP + - on Varnish 7, enable logging of access control list matching for both `invalidators` and `debuggers` lists + (new Varnish 7 syntax, it was enabled by default on previous versions) +3. Sets main `varnish*.vcl` file to use and "path to VCL directory" argument name depending on Varnish version +4. Copies the main VCL file to `.ddev/varnish/` +5. Sets the Varnish version to use and its demon starting parameters to use the files +6. Adds the Varnish container +7. Sets Varnish as the HTTP cache server +8. Restarts the DDEV cluster and clear the [[= product_name =]] cache + +```bash +VARNISH_VERSION=7.1 +mkdir -p .ddev/varnish +sed 's/.host = "127.0.0.1";/.host = "web";/' vendor/ibexa/http-cache/docs/varnish/vcl/parameters.vcl > .ddev/varnish/parameters.vcl +sed -i '/^acl invalidators {$/a \\ "web";' .ddev/varnish/parameters.vcl +sed -i '/^acl debuggers {$/a \\ "0.0.0.0"/0; \/\/ debug from any IP' .ddev/varnish/parameters.vcl +if [[ $VARNISH_VERSION == 7.* ]]; then + sed -i 's/acl invalidators {/acl invalidators +log {/' .ddev/varnish/parameters.vcl + sed -i 's/acl debuggers {/acl debuggers +log {/' .ddev/varnish/parameters.vcl + vcl_path=vcl_path + vcl_file=varnish7.vcl +elif [[ $VARNISH_VERSION == 6.* ]] + vcl_path=vcl_dir + vcl_file=varnish6.vcl +fi +cp vendor/ibexa/http-cache/docs/varnish/vcl/$vcl_file .ddev/varnish/ +ddev dotenv set .ddev/.env.varnish --varnish-docker-image=varnish:$VARNISH_VERSION --varnish-varnishd-params " -p $vcl_path=/etc/varnish -f /etc/varnish/$vcl_file" + +ddev get ddev/ddev-varnish + +ddev config --web-environment-add HTTPCACHE_PURGE_SERVER=http://varnish +ddev config --web-environment-add HTTPCACHE_PURGE_TYPE=varnish +ddev config --web-environment-add TRUSTED_PROXIES=varnish + +ddev restart +ddev php bin/console cache:clear +``` + +To use Varnish 6.0LTS, set the following variable instead: + +```bash +VARNISH_VERSION=6.0 +``` + +If you're using [Apache as web server](install_with_ddev.md#switch-to-apache-and-its-virtual-host), +you must set `varnish` as a trusted proxy in `.ddev/apache/apache-site.conf` before restarting DDEV: + +```bash +sed -i 's/#SetEnv TRUSTED_PROXIES ""/SetEnv TRUSTED_PROXIES "varnish"/' .ddev/apache/apache-site.conf + +ddev restart +``` + +The Varnish server acts as the application’s primary entry point. +If you run `ddev describe`, you can see that Varnish is now the one responding to DDEV domain `.ddev.site` +while the web server still replies to `127.0.0.1` with its own ports. + +You can see Varnish headers in HTTP responses, for example: + +```console +% curl -s -c cookies.txt -b cookies.txt -I https://.ddev.site:/ +HTTP/2 200 +server: Apache/2.4.65 (Debian) +vary: Origin,X-Editorial-Mode +via: 1.1 varnish (Varnish/7.1) +x-cache: HIT +x-cache-debug: 1 +x-cache-hits: 5 +x-cache-ttl: 87654.321 +x-debug-token: 012345 +x-debug-token-link: https://.ddev.site://_profiler/012345 +x-powered-by: Ibexa Commerce v5 +x-robots-tag: noindex +x-varnish: 12345 67890 +xkey: ez-all c52 ct42 l2 pl1 p1 p2 +content-length: 45678 +``` + +You can see how the `web` server is responding to `varnish`: + +```console +% curl -s -H "Surrogate-Capability: abc=ESI/1.0" http://127.0.0.1:/product-catalog | grep 'esi:include' +