Caddy does not compress the response

1. The problem I’m having:

Caddy does not compress the response

I use caddy behind a traefik reverse-proxy. The requests get passed to caddy correctly.
In the same docker container is php-fpm running via the github.com/baldinof/caddy-supervisor plugin.
However the Response-Headers do not show the “Content-Encoding: gzip” entry.

2. Error messages and/or full log output:

curl --compressed --dump-header - -o /dev/null https://foo.example.com/some-big.html

HTTP/2 200 
content-type: text/html;charset=UTF-8
date: Sun, 03 Sep 2023 13:46:02 GMT
server: Caddy
x-flow-powered: Flow/8.3 Neos/8.3
content-length: 80191

100 80191  100 80191    0     0   194k      0 --:--:-- --:--:-- --:--:--  194k

The Content-Length is higher than 512kb.

Example Log from one request:

{"level":"debug","ts":1693745805.0406754,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"10.0.2.232","remote_port":"59356","client_ip":"10.0.0.2","proto":"HTTP/1.1","method":"GET","host":"pathologie.c4c.it","uri":"/neos/administration/shel-neos-logs","headers":{"X-Real-Ip":["10.0.0.2"],"Referer":["https://pathologie.c4c.it/neos/content?node=%2Fsites%2Fpathologie%2Fnode-wrpn7x6agl58e%2Fnode-xr1309o84b8t4%40user-Fabian%3Blanguage%3Dde"],"Sec-Ch-Ua-Platform":["\"Linux\""],"Sec-Fetch-Dest":["document"],"Sec-Fetch-Site":["same-origin"],"X-Forwarded-For":["10.0.0.2"],"X-Forwarded-Port":["443"],"X-Forwarded-Server":["d97491ec0ffe"],"Accept-Encoding":["gzip, deflate, br"],"Cookie":[],"Sec-Fetch-User":["?1"],"Accept-Language":["de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"],"Upgrade-Insecure-Requests":["1"],"X-Forwarded-Host":["pathologie.c4c.it"],"X-Forwarded-Proto":["https"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Cache-Control":["max-age=0"],"Sec-Ch-Ua":["\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\""],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Mode":["navigate"]}},"method":"GET","uri":"/index.php"}
{"level":"debug","ts":1693745805.040736,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"/var/run/php/php-fpm.sock","total_upstreams":1}
{"level":"debug","ts":1693745805.0410075,"logger":"http.reverse_proxy.transport.fastcgi","msg":"roundtrip","request":{"remote_ip":"10.0.2.232","remote_port":"59356","client_ip":"10.0.0.2","proto":"HTTP/1.1","method":"GET","host":"pathologie.c4c.it","uri":"/index.php","headers":{"Sec-Ch-Ua-Mobile":["?0"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Mode":["navigate"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"],"Sec-Ch-Ua":["\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\""],"X-Real-Ip":["10.0.0.2"],"Sec-Ch-Ua-Platform":["\"Linux\""],"Sec-Fetch-Site":["same-origin"],"Cookie":[],"X-Forwarded-Proto":["https"],"X-Forwarded-Server":["d97491ec0ffe"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Cache-Control":["max-age=0"],"Referer":["https://pathologie.c4c.it/neos/content?node=%2Fsites%2Fpathologie%2Fnode-wrpn7x6agl58e%2Fnode-xr1309o84b8t4%40user-Fabian%3Blanguage%3Dde"],"Sec-Fetch-Dest":["document"],"X-Forwarded-For":["10.0.0.2, 10.0.2.232"],"Sec-Fetch-User":["?1"],"Accept-Language":["de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"],"X-Forwarded-Host":["pathologie.c4c.it"],"X-Forwarded-Port":["443"]}},"env":{"HTTP_UPGRADE_INSECURE_REQUESTS":"1","QUERY_STRING":"","REMOTE_HOST":"10.0.2.232","REMOTE_USER":"","HTTP_X_FORWARDED_FOR":"10.0.0.2, 10.0.2.232","GATEWAY_INTERFACE":"CGI/1.1","HTTP_X_FORWARDED_PORT":"443","HTTP_X_FORWARDED_SERVER":"d97491ec0ffe","HTTP_SEC_FETCH_SITE":"same-origin","SERVER_NAME":"pathologie.c4c.it","HTTP_ACCEPT_LANGUAGE":"de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7","HTTP_ACCEPT":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7","HTTP_SEC_CH_UA_MOBILE":"?0","HTTP_REFERER":"https://pathologie.c4c.it/neos/content?node=%2Fsites%2Fpathologie%2Fnode-wrpn7x6agl58e%2Fnode-xr1309o84b8t4%40user-Fabian%3Blanguage%3Dde","DOCUMENT_URI":"/index.php","HTTP_HOST":"pathologie.c4c.it","REQUEST_URI":"/neos/administration/shel-neos-logs","SERVER_PORT":"80","HTTP_SEC_FETCH_MODE":"navigate","REMOTE_ADDR":"10.0.2.232","REQUEST_METHOD":"GET","REQUEST_SCHEME":"http","SCRIPT_NAME":"/index.php","PATH_INFO":"","DOCUMENT_ROOT":"/srv/app/Web","SERVER_SOFTWARE":"Caddy/v2.7.4","HTTP_X_FORWARDED_HOST":"pathologie.c4c.it","HTTP_CACHE_CONTROL":"max-age=0","HTTP_SEC_FETCH_DEST":"document","AUTH_TYPE":"","REMOTE_IDENT":"","CONTENT_LENGTH":"","REMOTE_PORT":"59356","HTTP_SEC_CH_UA":"\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"","HTTP_X_REAL_IP":"10.0.0.2","HTTP_ACCEPT_ENCODING":"gzip, deflate, br","HTTP_USER_AGENT":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36","HTTP_COOKIE":"","HTTP_X_FORWARDED_PROTO":"https","CONTENT_TYPE":"","SERVER_PROTOCOL":"HTTP/1.1","SCRIPT_FILENAME":"/srv/app/Web/index.php","HTTP_SEC_FETCH_USER":"?1","HTTP_SEC_CH_UA_PLATFORM":"\"Linux\""},"dial":"/var/run/php/php-fpm.sock","env":{"GATEWAY_INTERFACE":"CGI/1.1","HTTP_X_FORWARDED_PORT":"443","HTTP_X_FORWARDED_SERVER":"d97491ec0ffe","SERVER_NAME":"pathologie.c4c.it","HTTP_ACCEPT_LANGUAGE":"de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7","HTTP_ACCEPT":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7","HTTP_SEC_CH_UA_MOBILE":"?0","HTTP_SEC_FETCH_SITE":"same-origin","DOCUMENT_URI":"/index.php","HTTP_HOST":"pathologie.c4c.it","REQUEST_URI":"/neos/administration/shel-neos-logs","SERVER_PORT":"80","HTTP_REFERER":"https://pathologie.c4c.it/neos/content?node=%2Fsites%2Fpathologie%2Fnode-wrpn7x6agl58e%2Fnode-xr1309o84b8t4%40user-Fabian%3Blanguage%3Dde","REMOTE_ADDR":"10.0.2.232","REQUEST_METHOD":"GET","REQUEST_SCHEME":"http","SCRIPT_NAME":"/index.php","HTTP_SEC_FETCH_MODE":"navigate","PATH_INFO":"","DOCUMENT_ROOT":"/srv/app/Web","AUTH_TYPE":"","REMOTE_IDENT":"","CONTENT_LENGTH":"","REMOTE_PORT":"59356","SERVER_SOFTWARE":"Caddy/v2.7.4","HTTP_X_FORWARDED_HOST":"pathologie.c4c.it","HTTP_CACHE_CONTROL":"max-age=0","HTTP_SEC_FETCH_DEST":"document","HTTP_SEC_CH_UA":"\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"","HTTP_X_REAL_IP":"10.0.0.2","CONTENT_TYPE":"","SERVER_PROTOCOL":"HTTP/1.1","SCRIPT_FILENAME":"/srv/app/Web/index.php","HTTP_SEC_FETCH_USER":"?1","HTTP_ACCEPT_ENCODING":"gzip, deflate, br","HTTP_USER_AGENT":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36","HTTP_COOKIE":"","HTTP_X_FORWARDED_PROTO":"https","HTTP_SEC_CH_UA_PLATFORM":"\"Linux\"","QUERY_STRING":"","REMOTE_HOST":"10.0.2.232","REMOTE_USER":"","HTTP_X_FORWARDED_FOR":"10.0.0.2, 10.0.2.232","HTTP_UPGRADE_INSECURE_REQUESTS":"1"},"request":{"remote_ip":"10.0.2.232","remote_port":"59356","client_ip":"10.0.0.2","proto":"HTTP/1.1","method":"GET","host":"pathologie.c4c.it","uri":"/index.php","headers":{"User-Agent":["Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"],"Sec-Ch-Ua":["\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\""],"Cookie":[],"X-Forwarded-Proto":["https"],"X-Forwarded-Server":["d97491ec0ffe"],"X-Real-Ip":["10.0.0.2"],"Sec-Ch-Ua-Platform":["\"Linux\""],"Sec-Fetch-Site":["same-origin"],"Sec-Fetch-User":["?1"],"Accept-Language":["de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"],"X-Forwarded-Host":["pathologie.c4c.it"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Cache-Control":["max-age=0"],"Referer":["https://pathologie.c4c.it/neos/content?node=%2Fsites%2Fpathologie%2Fnode-wrpn7x6agl58e%2Fnode-xr1309o84b8t4%40user-Fabian%3Blanguage%3Dde"],"Sec-Fetch-Dest":["document"],"X-Forwarded-For":["10.0.0.2, 10.0.2.232"],"X-Forwarded-Port":["443"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua-Mobile":["?0"]}}}
{"level":"debug","ts":1693745805.2948763,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"unix//var/run/php/php-fpm.sock","duration":0.254075014,"request":{"remote_ip":"10.0.2.232","remote_port":"59356","client_ip":"10.0.0.2","proto":"HTTP/1.1","method":"GET","host":"pathologie.c4c.it","uri":"/index.php","headers":{"Cookie":[],"X-Forwarded-Proto":["https"],"X-Forwarded-Server":["d97491ec0ffe"],"X-Real-Ip":["10.0.0.2"],"Sec-Ch-Ua-Platform":["\"Linux\""],"Sec-Fetch-Site":["same-origin"],"Sec-Fetch-User":["?1"],"Accept-Language":["de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"],"X-Forwarded-Host":["pathologie.c4c.it"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Cache-Control":["max-age=0"],"Referer":["https://pathologie.c4c.it/neos/content?node=%2Fsites%2Fpathologie%2Fnode-wrpn7x6agl58e%2Fnode-xr1309o84b8t4%40user-Fabian%3Blanguage%3Dde"],"Sec-Fetch-Dest":["document"],"X-Forwarded-For":["10.0.0.2, 10.0.2.232"],"X-Forwarded-Port":["443"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua-Mobile":["?0"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"],"Sec-Ch-Ua":["\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\""]}},"headers":{"Set-Cookie":[],"Content-Length":["28266"],"Content-Type":["text/html;charset=UTF-8"],"X-Flow-Powered":["Flow/8.3 Neos/8.3"]},"status":200}
- -  03/Sep/2023:12:56:45 +0000 "GET /index.php" 200

3. Caddy version:

v2.7.4 h1:J8nisjdOxnYHXlorUKXY75Gr6iBfudfoGhrJ8t7/flI=

4. How I installed and ran Caddy:

/usr/bin/caddy is copied from the caddy builder image

This is the shortened Dockerfile with all relevant parts:

# syntax=docker/dockerfile:1.4
FROM caddy:2-builder-alpine AS app_caddy_builder

RUN xcaddy build --with github.com/baldinof/caddy-supervisor --with github.com/ueffel/caddy-brotli


FROM php:8.2-fpm-alpine AS caddy
...
# php extensions installer: https://github.com/mlocati/docker-php-extension-installer
COPY --from=mlocati/php-extension-installer --link /usr/bin/install-php-extensions /usr/local/bin/

# persistent / runtime deps
RUN apk add --no-cache \
		acl \
		fcgi \
		file \
		gettext \
		git;

RUN set -eux; install-php-extensions imagick pdo_mysql redis intl zip;
...
COPY --from=app_caddy_builder /usr/bin/caddy /usr/bin/caddy
COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile
...
CMD ["caddy","run","--config","/etc/caddy/Caddyfile","--adapter","caddyfile"]

a. System environment:

Docker Container, as above

b. Command:

CMD as above

c. Service/unit/compose file:

I do know, that caddy and php should be in different containers. However the framework links resources to the public folder and therefore I wouldn’t be able to provide caddy with static resources.

version: "3.6"

services:
  neos:
    build:
      target: caddy
    labels:
      - traefik.enable=true
      - traefik.http.routers.pathologie-neos.rule=Host(`pathologie.c4c.it`)

traefik is working fine, as the logs show “Accept-Encoding” is passed correctly.

d. My complete Caddy config:

{
  auto_https off
  supervisor {
    php-fpm
    php flow nodeindexqueue:work --queue batch
    php flow nodeindexqueue:work --queue live
  }
  servers {
    trusted_proxies static private_ranges
  }
}

:80

route {
  root * /srv/app/Web
  php_fastcgi unix//var/run/php/php-fpm.sock
  encode zstd br gzip
  header ?Cache-Control "max-age=3600"
  header /_Resources/* Cache-Control max-age=31536000
  file_server
}

5. Links to relevant resources:

The problem is that you used route which forces directive order, then put encode after php_fastcgi, so the encoder is never enabled before php_fastcgi.

In your case, there’s no reason to use route. Remove that.

1 Like

Thank you. It works now.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.