diff --git a/docs/infrastructure_and_maintenance/clustering/clustering_with_ddev.md b/docs/infrastructure_and_maintenance/clustering/clustering_with_ddev.md index 680c0b7ff8..55ad765116 100644 --- a/docs/infrastructure_and_maintenance/clustering/clustering_with_ddev.md +++ b/docs/infrastructure_and_maintenance/clustering/clustering_with_ddev.md @@ -27,6 +27,119 @@ 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 + +### Varnish + +The following sequence of commands: + +1. Set some variables to distinguish Varnish versions, here for Varnish 7.1 +2. Copy and customize VCL files in `.ddev/varnish/` (which is mounted as `/etc/varnish/` into the container) + - set `web` container has the backend host and an invalidator (so back office can purge cache) + - add "all IPs" CIDR notation to `debuggers` list to allow debugging info 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. Set the Varnish version to use and its demon starting parameters to use the files +4. Adds the Varnish container +5. Sets Varnish as the HTTP cache server +6. Restarts the DDEV cluster + +```bash +VARNISH_VERSION=7.1 +vcl_path=vcl_path +vcl_file=varnish7.vcl +mkdir -p .ddev/varnish +cp vendor/ibexa/http-cache/docs/varnish/vcl/$vcl_file .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 +fi +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 +``` + +To use Varnish 6.0LTS, set the following variables instead: + +```bash +VARNISH_VERSION=6.0 +vcl_path=vcl_dir +vcl_file=varnish6.vcl +``` + +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 replace the web server in some places. +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-ibexa-tmp2.ddev.site:8443/_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' +