Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,23 @@ Make sure to commit the `.ddev/.env.varnish` file to version control.

All customization options (use with caution):

| Variable | Flag | Default |
| -------- | ---- | ------- |
| `VARNISH_DOCKER_IMAGE` | `--varnish-docker-image` | `varnish:6.0` |
| Variable | Flag | Default |
|---------------------------|-----------------------------|--------------------------------------------------------------------------------------------------------------------|
| `VARNISH_DOCKER_IMAGE` | `--varnish-docker-image` | `varnish:6.0` |
| `VARNISH_VARNISHD_PARAMS` | `--varnish-varnishd-params` | `-p http_max_hdr=1000 -p http_resp_hdr_len=1M -p http_resp_size=2M -p workspace_backend=3M -p workspace_client=3M` |

### VARNISH_VARNISHD_PARAMS

Allows modifying the varnish [startup parameters](https://varnish-cache.org/docs/6.0/reference/varnishd.html).

The provided defaults are set deliberately higher than what varnish usually defines.
The reason for this is that in development environments it is not uncommon to
have larger payloads either in HTML or HTTP-Headers. E.g. Drupals theme debugging
or cache tag handling.
Without increasing these limits, one might encounter hard to isolate errors like the following form nginx:
```
2025/07/15 09:01:01 [info] 1549#1549: *259 writev() failed (32: Broken pipe) while sending to client, client: 172.20.0.6, server: , request: "GET /en HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm.sock:", host: "myproject.ddev.site"
```

## Credits

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.varnish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ services:
expose:
- "8025"
entrypoint:
/usr/local/bin/docker-varnish-entrypoint -a 0.0.0.0:8025
/usr/local/bin/docker-varnish-entrypoint -a 0.0.0.0:8025 ${VARNISH_VARNISHD_PARAMS:--p http_max_hdr=1000 -p http_resp_hdr_len=1M -p http_resp_size=2M -p workspace_backend=3M -p workspace_client=3M}
48 changes: 48 additions & 0 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ setup() {

run ddev start -y
assert_success
export CUSTOM_VARNISH_VARNISHD_PARAMS=false
}

health_checks() {
Expand All @@ -61,6 +62,36 @@ health_checks() {
curl -sfI "http://${PROJNAME}.ddev.site:${MAILPIT_HTTP_PORT}/" | grep -i "http://novarnish.${PROJNAME}.ddev.site:${MAILPIT_HTTP_PORT}/" >/dev/null || (echo "# http://${PROJNAME}.ddev.site:${MAILPIT_HTTP_PORT} did not redirect" >&3 && exit 1);
echo "# test https://${PROJNAME}.ddev.site:${MAILPIT_HTTPS_PORT}/ for https novarnish redirect" >&3
curl -sfI "https://${PROJNAME}.ddev.site:${MAILPIT_HTTPS_PORT}/" | grep -i "https://novarnish.${PROJNAME}.ddev.site:${MAILPIT_HTTPS_PORT}/" >/dev/null || (echo "# https://${PROJNAME}.ddev.site:${MAILPIT_HTTPS_PORT} did not redirect" >&3 && exit 1);

if [ "${CUSTOM_VARNISH_VARNISHD_PARAMS}" = "true" ]; then
run ddev varnishadm param.show http_max_hdr
assert_success
assert_output --partial 'Value is: 123 [header lines]'

run ddev varnishadm param.show http_resp_hdr_len
assert_success
assert_output --partial 'Value is: 16k [bytes]'
else
run ddev varnishadm param.show http_max_hdr
assert_success
assert_output --partial 'Value is: 1000 [header lines]'

run ddev varnishadm param.show http_resp_hdr_len
assert_success
assert_output --partial 'Value is: 1M [bytes]'

run ddev varnishadm param.show http_resp_size
assert_success
assert_output --partial 'Value is: 2M [bytes]'

run ddev varnishadm param.show workspace_backend
assert_success
assert_output --partial 'Value is: 3M [bytes]'

run ddev varnishadm param.show workspace_client
assert_success
assert_output --partial 'Value is: 3M [bytes]'
fi
}

teardown() {
Expand Down Expand Up @@ -104,3 +135,20 @@ teardown() {
export ROUTER_HTTP_PORT=8080 ROUTER_HTTPS_PORT=8443 MAILPIT_HTTP_PORT=18025 MAILPIT_HTTPS_PORT=18026
health_checks
}

@test "customize varnishd startup parameters" {
set -eu -o pipefail
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in $(pwd)" >&3
run ddev add-on get "${DIR}"
assert_success
run ddev dotenv set .ddev/.env.varnish --varnish-varnishd-params='-p http_max_hdr=123 -p http_resp_hdr_len=16k'
assert_success
run cat .ddev/.env.varnish
assert_success
assert_output 'VARNISH_VARNISHD_PARAMS="-p http_max_hdr=123 -p http_resp_hdr_len=16k"'
run ddev restart -y
assert_success
export ROUTER_HTTP_PORT=80 ROUTER_HTTPS_PORT=443 MAILPIT_HTTP_PORT=8025 MAILPIT_HTTPS_PORT=8026
export CUSTOM_VARNISH_VARNISHD_PARAMS=true
health_checks
}