Can't disable gzip encoding for specific path with `not path`matcher

1. Caddy version (caddy version):

Latest ofcourse :smiley:
v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

with Systemd

a. System environment:

CentOS Linux release 7.7.1908 (Core)

b. Command:

systemd start caddy

c. Service/unit/compose file:

cat /etc/systemd/system/caddy.service 
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
User=root
Group=root
ExecStart=/usr/bin/caddy run --config /home/eportal/Caddyfile
ExecReload=/usr/bin/caddy reload --config /home/eportal/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

{
    experimental_http3
}

eportal.skilnet.no  {
    root * /home/eportal/production/current/public
    try_files {path} /index.php?{query}
    php_fastcgi 127.0.0.1:9000
    file_server

    @notMeasure {
	not path /api/nefle_video/measure*
    }

    encode @notMeasure gzip zstd
}

3. The problem I’m having:

any requests to https://eportal.skilnet.no/api/nefle_video/measure?module=download is gzip encoded, but it’s not supposed to be encoded, I want this url to be raw content…

4. Error messages and/or full log output:

- Logs begin at fr. 2018-05-18 10:15:54 CEST. --
mai 11 16:36:43 vps.skilnet.no caddy[23625]: 2020/05/11 16:36:43 [DEBUG] Fake-closing underlying packet conn
mai 11 16:36:43 vps.skilnet.no caddy[23625]: 2020/05/11 16:36:43 [INFO][cache:0xc0003eae10] Stopped certificate maintenance routine
mai 11 16:36:43 vps.skilnet.no caddy[23625]: {"level":"info","ts":1589207803.648101,"msg":"autosaved config","file":"/root/.config/caddy/autosave.json"}
mai 11 16:36:43 vps.skilnet.no caddy[23625]: {"level":"info","ts":1589207803.6481125,"logger":"admin.api","msg":"load complete"}
mai 11 16:36:44 vps.skilnet.no caddy[23625]: {"level":"info","ts":1589207804.1475358,"logger":"admin","msg":"stopped previous server"}
mai 11 16:41:11 vps.skilnet.no caddy[23625]: {"level":"info","ts":1589208071.913783,"logger":"admin.api","msg":"received request","method":"POST","host":"localhost:2019","uri":"/load","remote_addr":"127.0.0.1:60324","headers":{"Accept-Encoding":["gzip"],"Content-Length":["1361"],"Content-Type":["application/json"],"Origin":["localhost:2019"],"User-Agent":["Go-http-client/1.1"]}}
mai 11 16:41:11 vps.skilnet.no caddy[23625]: {"level":"info","ts":1589208071.9140646,"logger":"admin.api","msg":"config is unchanged"}
mai 11 16:41:11 vps.skilnet.no caddy[23625]: {"level":"info","ts":1589208071.9140725,"logger":"admin.api","msg":"load complete"}
mai 11 16:42:26 vps.skilnet.no caddy[23625]: 2020/05/11 16:42:26 http: TLS handshake error from 104.199.36.222:20014: no certificate available for '10.19.0.5'
mai 11 16:47:04 vps.skilnet.no caddy[23625]: 2020/05/11 16:47:04 http: TLS handshake error from 198.108.66.204:33878: no certificate available for '46.101.126.224'

5. What I already tried:

Reading the documentation, trying different paths (I only tried measure as well as the current one, but no success)

6. Links to relevant resources:

Hmm, your config does look right.

Could you provide logs that show a request to the path you’re trying to fix? The logs you gave aren’t showing relevant information here. You might need to add the log directive to make more info appear.

I don’t think this is necessary for you here. The php_fastcgi directive does its own try_files, so I’m pretty certain you can just remove this line without issue!

1 Like

Can you also confirm that your PHP application is not gzipping the content itself?

1 Like

Hi!

Scratch that, it works! I don’t know what changed, but I added output logging, and it seems to be working now (everything except my measure endpoint is gzipped)!

For future reference, here is my current Caddyfile:

{
    experimental_http3
}


eportal.skilnet.no  {
    root * /home/eportal/production/current/public
    php_fastcgi 127.0.0.1:9000
    file_server
    
    log {
        output stdout
    }
    
    @notMeasure {
        not path /api/nefle_video/measure*
    }

    encode @notMeasure gzip zstd

}

I had no idea php-fpm supported output compression, but I double checked, and it is off.

Here is the request-log:

mai 12 09:17: 23 vps.skilnet.no caddy[23625]:
{
  "level": "info",
  "ts": 1589267843.5657258,
  "logger": "http.log.access.log0",
  "msg": "handled request",
  "request": {
    "method": "GET",
    "uri": "/api/nefle_video/measure?module=download",
    "proto": "HTTP/2.0",
    "remote_addr": "92.221.87.36:60726",
    "host": "eportal.skilnet.no",
    "headers": {
      "Upgrade-Insecure-Requests": [
        "1"
      ],
      "Te": [
        "trailers"
      ],
      "User-Agent": [
        "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"
      ],
      "Accept": [
        "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
      ],
      "Accept-Language": [
        "nb,no;q=0.8,en-US;q=0.5,en;q=0.3"
      ],
      "Accept-Encoding": [
        "gzip, deflate, br"
      ],
      "Cookie": [
        "_ga=GA1.2.201503905.1583329031; eportal_auth=s019n9fg5tmo1uvb4aen0eo4sm"
      ]
    },
    "tls": {
      "resumed": false,
      "version": 772,
      "ciphersuite": 4865,
      "proto": "h2",
      "proto_mutual": true,
      "server_name": "eportal.skilnet.no"
    }
  },
  "common_log": "92.221.87.36 - - [12/May/2020:09:17:23 +0200] \"GET /api/nefle_video/measure?module=download HTTP/2.0\" 200 20971520",
  "duration": 0.449580672,
  "size": 20971520,
  "status": 200,
  "resp_headers": {
    "Link": [
      "<https://eportal.skilnet.no/api/docs.jsonld>; rel=\"http://www.w3.org/ns/hydra/core#apiDocumentation\""
    ],
    "Expires": [
      "Tue, 12 May 2020 07:17:23 GMT"
    ],
    "X-Powered-By": [
      "PHP/7.4.5"
    ],
    "Cache-Control": [
      "max-age=0, must-revalidate, no-cache, no-store, private"
    ],
    "Date": [
      "Tue, 12 May 2020 07:17:23 GMT"
    ],
    "Server": [
      "Caddy"
    ],
    "Alt-Svc": [
      "h3-27=\":443\"; ma=2592000"
    ],
    "Content-Type": [
      "text/html; charset=UTF-8"
    ]
  }
}
3 Likes

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