Skip to content

Commit 98e1010

Browse files
committed
feat: Provide environment variable to customize varnishd startup parameters and increase
1 parent 32ee3a5 commit 98e1010

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,23 @@ Make sure to commit the `.ddev/.env.varnish` file to version control.
6565

6666
All customization options (use with caution):
6767

68-
| Variable | Flag | Default |
69-
| -------- | ---- | ------- |
70-
| `VARNISH_DOCKER_IMAGE` | `--varnish-docker-image` | `varnish:6.0` |
68+
| Variable | Flag | Default |
69+
|---------------------------|-----------------------------|--------------------------------------------------------------------------------------------------------------------|
70+
| `VARNISH_DOCKER_IMAGE` | `--varnish-docker-image` | `varnish:6.0` |
71+
| `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` |
72+
73+
### VARNISH_VARNISHD_PARAMS
74+
75+
Allows modifying the varnish [startup parameters](https://varnish-cache.org/docs/6.0/reference/varnishd.html).
76+
77+
The provided defaults are set deliberately higher than what varnish usually defines.
78+
The reason for this is that in development environments it is not uncommon to
79+
have larger payloads either in HTML or HTTP-Headers. E.g. Drupals theme debugging
80+
or cache tag handling.
81+
Without increasing these limits, one might encounter hard to isolate errors like the following form nginx:
82+
```
83+
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"
84+
```
7185

7286
## Credits
7387

docker-compose.varnish.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ services:
2828
expose:
2929
- "8025"
3030
entrypoint:
31-
/usr/local/bin/docker-varnish-entrypoint -a 0.0.0.0:8025
31+
/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}

tests/test.bats

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ setup() {
4141

4242
run ddev start -y
4343
assert_success
44+
export CUSTOM_VARNISH_VARNISHD_PARAMS=false
4445
}
4546

4647
health_checks() {
@@ -61,6 +62,36 @@ health_checks() {
6162
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);
6263
echo "# test https://${PROJNAME}.ddev.site:${MAILPIT_HTTPS_PORT}/ for https novarnish redirect" >&3
6364
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);
65+
66+
if [ "${CUSTOM_VARNISH_VARNISHD_PARAMS}" = "true" ]; then
67+
run ddev varnishadm param.show http_max_hdr
68+
assert_success
69+
assert_output --partial 'Value is: 123 [header lines]'
70+
71+
run ddev varnishadm param.show http_resp_hdr_len
72+
assert_success
73+
assert_output --partial 'Value is: 16k [bytes]'
74+
else
75+
run ddev varnishadm param.show http_max_hdr
76+
assert_success
77+
assert_output --partial 'Value is: 1000 [header lines]'
78+
79+
run ddev varnishadm param.show http_resp_hdr_len
80+
assert_success
81+
assert_output --partial 'Value is: 1M [bytes]'
82+
83+
run ddev varnishadm param.show http_resp_size
84+
assert_success
85+
assert_output --partial 'Value is: 2M [bytes]'
86+
87+
run ddev varnishadm param.show workspace_backend
88+
assert_success
89+
assert_output --partial 'Value is: 3M [bytes]'
90+
91+
run ddev varnishadm param.show workspace_client
92+
assert_success
93+
assert_output --partial 'Value is: 3M [bytes]'
94+
fi
6495
}
6596

6697
teardown() {
@@ -104,3 +135,23 @@ teardown() {
104135
export ROUTER_HTTP_PORT=8080 ROUTER_HTTPS_PORT=8443 MAILPIT_HTTP_PORT=18025 MAILPIT_HTTPS_PORT=18026
105136
health_checks
106137
}
138+
139+
@test "customize varnishd startup parameters" {
140+
set -eu -o pipefail
141+
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in $(pwd)" >&3
142+
run ddev add-on get "${DIR}"
143+
assert_success
144+
run ddev dotenv set .ddev/.env.varnish --varnish-varnishd-params='-p http_max_hdr=123 -p http_resp_hdr_len=16k'
145+
assert_success
146+
run cat .ddev/.env.varnish
147+
assert_success
148+
assert_output 'VARNISH_VARNISHD_PARAMS="-p http_max_hdr=123 -p http_resp_hdr_len=16k"'
149+
run ddev restart -y
150+
assert_success
151+
export ROUTER_HTTP_PORT=80 ROUTER_HTTPS_PORT=443 MAILPIT_HTTP_PORT=8025 MAILPIT_HTTPS_PORT=8026
152+
export CUSTOM_VARNISH_VARNISHD_PARAMS=false
153+
health_checks
154+
run ddev varnishadm param.show http_max_hdr
155+
assert_output --partial 'Value is: 123 [header lines]'
156+
assert_success
157+
}

0 commit comments

Comments
 (0)