static directory index fails with an explicit try_files configuration
Issue Details
I encountered the same issue on Caddy v2.11.9, running in Docker.
My setup uses both php_fastcgi and file_server. The problem occurs when accessing a directory that contains an index.html file but does not have an index.php file.
Environment
- Caddy version:
v2.11.9 - Deployment: Docker
- PHP backend: PHP-FPM (separate container)
Caddyfile
Here is a simplified version of my configuration:
example.test:80 {
root * /srv/site
php_fastcgi php-fpm:9000 {
try_files {path} {path}/index.php
}
file_server
}
Directory structure
/srv/site/
└── xxxxxx/
└── index.html
There is an index.html inside the wxwork directory, but no index.php in that directory.
Steps to reproduce
- Start Caddy v2.11.9 with the configuration above.
- Request
/xxxxxx/. - Request
/xxxxxx/index.htmldirectly.
Actual behavior
GET /xxxxxx/returns404with the response bodyFile not found.GET /xxxxxx/index.htmlworks correctly and serves the HTML file.
Expected behavior
When requesting /xxxxxx/, Caddy should detect the existing index.html and serve it through file_server, rather than attempting to execute a non-existent PHP index file through PHP-FPM.
Direct requests to existing PHP files should continue to be handled by php_fastcgi as usual.
Additional notes
The issue appeared after upgrading Caddy. The same configuration worked correctly with the previous version.
The index.html file is present and accessible from the Caddy container, as demonstrated by the fact that requesting /xxxxxx/index.html directly works.
One detail worth investigating is that this configuration explicitly specifies:
try_files {path} {path}/index.php
Could you confirm whether the fix in #8372 also addresses this explicit try_files configuration?
Thank you!
Assistance Disclosure
AI used
If AI was used, describe the extent to which it was used.
ChatGPT translated from my native language
I tested this with the exact config from the report, using a stub FastCGI upstream that echoes SCRIPT_FILENAME, a directory xxxxxx/ containing only index.html, and a second directory phpdir/ containing index.php. Same test run against two revisions:
v2.11.9 (tag 0d98caea) — reproduces the report
GET /xxxxxx/is rewritten to/xxxxxx/index.phpand handed to FastCGI, even though that file does not exist. With a real PHP-FPM that is the 404File not found.from the report.GET /missingis also rewritten to/missing/index.php.
master (f458aa00) — fixed
GET /xxxxxx/returns 200 with theindex.htmlcontent, served byfile_server.GET /phpdir/still rewrites to the existingindex.phpand is proxied.- Direct requests to existing
.phpfiles are still proxied. GET /missingreturns 404 fromfile_server, nothing is passed to FastCGI.
The difference is #8372. It removed the try_policy that parsePHPFastCGI used to infer for php_fastcgi, in all cases and not only for the default try_files, so an explicit try_files {path} {path}/index.php now gets first_exist behaviour instead of first_exist_fallback. (The PR note about explicitly configured first_exist_fallback keeping its semantics still holds where a policy can actually be set by hand, i.e. on a file matcher.) v2.11.9 was released 2026-11-05, before #8372 merged, so the fix should ship in the next release.
Assistance Disclosure
AI was used to help run the A/B test described above and to draft this comment. The test results were verified against both revisions before posting.
can i work on this