I got a log, the rewrite does happen before php_fastcgi. Relevant lines (with a replaced actual domain):
{"level":"debug","ts":1645289708.9771225,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_addr":"192.168.1.2:43136","proto":"HTTP/2.0","method":"GET","host":"nc.example.com","uri":"/.well-known/caldav","headers":{"User-Agent":["curl/7.68.0"],"Accept":["*/*"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"nc.example.com"}},"method":"GET","uri":"/remote.php/dav"}
{"level":"debug","ts":1645289708.9771683,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_addr":"192.168.1.2:43136","proto":"HTTP/2.0","method":"GET","host":"nc.example.com","uri":"/remote.php/dav","headers":{"User-Agent":["curl/7.68.0"],"Accept":["*/*"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"nc.example.com"}},"method":"GET","uri":"/remote.php"}
{"level":"debug","ts":1645289708.977239,"logger":"http.reverse_proxy.transport.fastcgi","msg":"roundtrip","request":{"remote_addr":"192.168.1.2:43136","proto":"HTTP/2.0","method":"GET","host":"nc.example.com","uri":"/remote.php","headers":{"User-Agent":["curl/7.68.0"],"Accept":["*/*"],"X-Real-Ip":["192.168.1.2"],"X-Forwarded-For":["192.168.1.2"],"X-Forwarded-Proto":["https"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"nc.example.com"}},"dial":"127.0.0.1:9000","env":{"AUTH_TYPE":"","CONTENT_LENGTH":"","CONTENT_TYPE":"","DOCUMENT_ROOT":"/var/www/html","DOCUMENT_URI":"/remote.php","GATEWAY_INTERFACE":"CGI/1.1","HTTPS":"on","HTTP_ACCEPT":"*/*","HTTP_HOST":"nc.example.com","HTTP_USER_AGENT":"curl/7.68.0","HTTP_X_FORWARDED_FOR":"192.168.1.2","HTTP_X_FORWARDED_PROTO":"https","HTTP_X_REAL_IP":"192.168.1.2","PATH_INFO":"/dav","PATH_TRANSLATED":"/var/www/html/dav","QUERY_STRING":"","REMOTE_ADDR":"192.168.1.2","REMOTE_HOST":"192.168.1.2","REMOTE_IDENT":"","REMOTE_PORT":"43136","REMOTE_USER":"","REQUEST_METHOD":"GET","REQUEST_SCHEME":"https","REQUEST_URI":"/.well-known/caldav","SCRIPT_FILENAME":"/var/www/html/remote.php","SCRIPT_NAME":"/remote.php","SERVER_NAME":"nc.example.com","SERVER_PROTOCOL":"HTTP/2.0","SERVER_SOFTWARE":"Caddy/v2.4.6","SSL_CIPHER":"TLS_AES_128_GCM_SHA256","SSL_PROTOCOL":"TLSv1.3","front_controller_active":"true"}}
In the request to php-fpm 127.0.0.1:9000 these look possibly wrong:
"DOCUMENT_URI": "/remote.php",
"PATH_INFO": "/dav",
"PATH_TRANSLATED": "/var/www/html/dav",
php-fpm logs show "GET /remote.php" 404
but if I directly request /remote.php/dav
it works. It appears there’s some confusion in the path/doc root when rewriting a path and passing it to php-fpm.
Does this look like a Caddy bug?